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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

preg_replace ignore certain string

Status
Not open for further replies.

BigBadDave

Programmer
May 31, 2001
1,069
EU
I have been making my own mark-up a bit like TGML :

function parseBDML($string) {
$search = array ("/\[sup\]/",
"/\[\/sup\]/",
"/\[sub\]/",
"/\[\/sub\]/",
"/\[s\]/",
"/\[\/s\]/");
$replace = array (&quot;<sup>&quot;,
&quot;</sup>&quot;,
&quot;<sub>&quot;,
&quot;</sub>&quot;,
&quot;<s>&quot;,
&quot;</s>&quot;);
return stripslashes(preg_replace ($search, $replace, $string));
}

But I want to have a \[code\] | \[ignore\] tag (just like TGML) how do I make the regex ignore stuff between these tags ?? Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
just use a '^' as the first symbol in a bracket expression (i.e., &quot;%[^a-zA-Z]%&quot; matches a string with a character that is not a letter between two percent signs ***************************************
Party on, dudes!
[cannon]
 
I don't get it can you explain?? Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
if you use a regexp, normally you will search for stuff like [a-zA-Z0-9] this will show you any letter or number and in any case.

If you dont want something you use [^abc] which would ignore abc but return everything else.

ry this page for help : I have it bookmarked as regexp is such a wife :) ***************************************
Party on, dudes!
[cannon]
 
No thats not what I meant

I want to stop the search and replace from doing its thing when it reads \[code\] or \[ignore\] tags (without the slashes) Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
Anybody have an Idea? Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
Been playing around with ereg, eregi and preg_match today, but still I can't get my head round making the code avoid the bits you want to preserve.

Will need to think on a few pints .. doesn't normally help solve problems but it makes me feel better :)


***************************************
Party on, dudes!
[cannon]
 
Perhaps if you use a sub-match. Without any special formatting, this is what I mean...
[ignore]
Code:
(*)
[/ignore]
then you can replace with everything inside the sub-match, using $submatch[1] or something to that effect...

Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top