Hi,
What is the PHP preg_replace in C#?
I have an array of string that I would like to replace by an other array of string. Here is an example in PHP. How can I do something like that in C# without using .Replace("old","new").
$patterns[0] = '/=C0/';
$patterns[1] = '/=E9/';
$patterns[2] = '/=C9/';
$replacements[0] = 'à';
$replacemen...
I'm pretty new to regular expressions.
I have a requirement to replace spaces in a piece of multi-line text. The replacement rules are these:
Replace all spaces at start-of-line with a non-breaking space ( )
Replace any instance of repeated spaces (more than one space together) with the same number of non-breaking-spaces
Single s...
Hi all,
First post, so here goes. I'm writing a script that does intelligent search and replace on a file tree. Essentially, the script gets each file's contents into a buffer string and performs a match with a pre-defined pattern, in this case the pattern is /^[^\r\n]*(vendor)[^\r\n]*$/im. The pattern should find any case-insensitive f...
Hi Guys I'm very new to regex, can you help me with this.
I have a string like this "<input attribute='value' >" where attribute='value' could be anything and I want to get do a preg_replace to get just <input />
How do I specify a wildcard to replace any number of any characters in a srting?
like this? preg_replace("/<input.*>/",$r...
I need advice on this snippet
$text = preg_replace('|(A.*)?A(.*)C|', '$1foo$2bar', $text);
This will match ABC in "AB ABC D", and replace it with "AB fooBbar D"; as you can see this matches the "AB " part at the beginning as well, which I have to repeat in the replacement string with $1, in order not to lose it.
Is this the best way ...
Hello,
I want to parse a file and I want to use php and regex to strip:
blank or empty lines
single line comments
multi line comments
basically I want to remove any line containing
/* text */
or multi line comments
/***
some
text
*****/
If possible, another regex to check if the line is empty (Remove blank lines)
Is that pos...
i'm having a memory issue while testing a find/replace function.
Say the search subject is:
$subject = "I wrote an article in the A+ magazine.
It'\s very long and full of words.
I want to replace every A+ instance in this text by a link
to a page dedicated to A+.";
the string to be found :
$find='A+';
$find = preg_quote($find...
I need to read a string, detect a {VAR}, and then do a file_get_contents('VAR.php') in place of {VAR}. The "VAR" can be named anything, like TEST, or CONTACT-FORM, etc. I don't want to know what VAR is -- not to do a hard-coded condition, but to just see an uppercase alphanumeric tag surrounded by curly braces and just do a file_get_cont...
I need a PHP solution to get rid of commas inside double quotes. I can't seem to figure out a solution using preg_replace.
I'm inserting data into a database from a text file that is coma delimited.
Certain columns from the text file contain multiple words that are surrounded in double quotes. Theses double quotes have comas inside, so...
I have the following string replacement problem and I am in quite a fix here
PFB the sample string
$string = 'The quick sample_text_1 56 quick sample_text_2 78 fox jumped over the lazy dog.';
$patterns[0] = '/quick/';
$patterns[1] = '/quick/';
$patterns[2] = '/fox/';
$replacements[2] = 'bear';
$replacements[1] = 'black';
$replacement...
I have the following:
$reg[0] = '`<a(\s[^>]*)href="([^"]*)"([^>]*)>`si';
$reg[1] = '`<a(\s[^>]*)href="([^"]*)"([^>]*)>`si';
$replace[0] = '<a$1href="http://www.yahoo.com"$3>';
$replace[1] = '<a$1href="http://www.live.com"$3>';
$string = 'Test <a href="http://www.google.com">Google!!</a>Test <a href="http://www.google.com"...
Hi,
I am using preg_replace to escape special characters...
$tmpStr=preg_replace("/\?/", "\?", $tmpStr);
$tmpStr=preg_replace("/\#/", "\#", $tmpStr);
$tmpStr=preg_replace("/\^/", "\^", $tmpStr);
$tmpStr=preg_replace("/\&/", "\&", $tmpStr);
$tmpStr=preg_replace("/\*/", "\*", $tmpStr);
...
OK,I know that I should use a DOM parser, but this is to stub out some code that's a proof of concept for a later feature, so I want to quickly get some functionality on a limited set of test code.
I'm trying to strip the width and height attributes of chunks HTML, in other words, replace
width="number" height="number"
with a blank s...
So I have some PHP code that looks like:
$message = 'Here is the result: %s';
I just used %s as an example. It's basically a placeholder for whatever will go there. Then I pass the string to a function and I want that function to replace the %s with the value.
What do I need to do to achieve this? Do I need to do some regex, and use ...
I'm using TinyMCE (WYSIWYG) as the default editor in one of my projects and sometimes it automatically adds <p> </p> , <p> </p> or divs.
I have been searching but I couldn't really find a good way of cleaning any empty tags with regex.
The code I've tried to used is,
$pattern = "/<[^\/>]*>([\s]?)*<\/[^>]*>/";
$str = preg_replace(...
Hey, what's the most effective way to remove beginning and ending slashes from all rows in a particular column using MySQL?
Before:
/hello/world/
foo/bar/
/something/else
/one/more/*
After:
hello/world
foo/bar
something/else
one/more/*
...or maybe this should be done in PHP instead?
...
I need to remove the first forward slash inside link formatted like this:
/directory/link.php
I need to have:
directory/link.php
I'm not literate in regular expressions (preg_replace?) and those slashes are killing me..
I need your help stackoverflow!
Thank you very much!
...
I seem to have confused myself with a preg_match regex I'm doing, so fresh eyes and help would be appreciated.
My current regex is as follows:
/<!--menu:start:\(([0-9])\,([0-9])\)-->(.*?)<!--menu:end-->/se
I am looking to make the number input and colon e.g. :(1,4) optional, so it would match:
<!--menu:start--><!--menu:end-->
or
...
I keep getting this error:
Warning: preg_match()
[function.preg-match]: Unknown
modifier 't' in
D:\xampp\htdocs\administrator\components\com_smms\functions\plugin.php
on line 235
on:
$PageContent = preg_replace($result->module_pregmatch, '', $PageContent);
I do a var_dump on the $result->module_pregmatch and I get the fo...
With PHP, I'd like to use a preg_replace() filter for passwords such that the only characters available for passwords are US ASCII typable, minus control codes and NULL.
What's the RegEx to achieve that which I can plugin to preg_replace()?
EDIT:
I've been advised to edit this question since I "get it" now and won't be doing this terr...