PHP: regex & hash key in string

wademadrid

New Member
How do I address special characters in Regex? \[code\]@ ? # $ % %...\[/code\]
this patten searches for a letter that comes between a prefix and a suffix.\[code\]$pattern = '/((?<!\b$PREFIX)$LETTER|$LETTER(?!$SUFFIX\b))/i';$string = 'end'; $prefix = 'e'; $letter = 'n'; $suffix = 'd'; \[/code\]But what if \[code\]$string\[/code\] began with a \[code\]#\[/code\] \[code\]$string = '#end';$prefix = ???\[/code\]edit: This is the preg_replace in full \[code\]$text = "<p>Newton, Einsteing and Edison. #end</p>"$pattern = '/((?<!\b$PREFIX)$LETTER|$LETTER(?!$SUFFIX\b))/i';echo preg_replace($pattern, '<b>\1</b>', $text);\[/code\]this replaces all the \[code\]n\[/code\] letters with a bold \[code\]n\[/code\] but is supposed to exculde the \[code\]n\[/code\] in \[code\]#end\[/code\]
 
Back
Top