Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expressions

Status
Not open for further replies.

Android

Programmer
Joined
Jul 30, 1999
Messages
7
Location
US
OK, i'm not very familiar with regular expressions but i have a feeling this is a simple problem. I just need someone to enlighten me.<br>
<br>
I need to replace the # character inside a string with another string. Easy enough.. i just use "#" as my pattern to match and give the string to replace it...<br>
<br>
but what i also want to do is not replace the # character if it is preceded by a backslash... and also not display the backslash... so, lets say that i'm replacing the "#" with "123".<br>
<br>
"blah#blah" should become "blah123blah"<br>
<br>
but "foo\#bar" should be "foo#bar" (without the backslash showing)<br>
<br>
any ideas?<br>
<br>

 
Give a sample ereg to extract a URL or email from a string. <br><br>$file_array = file($fileName);<br>for ($i=0; $i&lt;count($file_array); $i++){<br>&nbsp;&nbsp;ereg( ?? );<br>}<br><br><br>where any line of text may contain a valid URL or email.<br>
 
Hi<br><br>I've an other question: how can I specify that the wildcards not to be so hungry.<br><br>ereg(&quot;(.*)X&quot;,&quot;abXcdX&quot;,$regs);<br>$regs[1] will be: &quot;abXcd&quot;, but I would need &quot;ab&quot;<br><br>Thanks in advance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top