Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
Thread: RegEx help
06-05-2005, 09:48 PM #1
I'm using the WP plugin Acronym Replacer, and I'm trying to make it ignore any acronyms inside <code> and <pre> elements. The default 2.8 code is:PHP Code:
$text = preg_replace("|(?!<[^<>]*?)(?<![?./&])\b$acronym\b(?!:)(?![^<>]*?>)|imsU","<acronym title=\"$description\">$acronym</acronym>" , $text);
06-06-2005, 11:19 AM #2
- Join Date
- Jun 2002
- frankfurt, german banana republic
- Thanked 0 Times in 0 Posts
This is probably too much for a regexp. Although the PREG engine is very powerful and adds alot of useful extensions for creating sophisticated regular expressions, it's still not a parser. But the behaviour you asked for requires that information about the parsing state must be accessible (whether the parser is currently inside/outside a <code> element). So the answer is: You need to write your own parser for it and invoke the regexp depending on the circumstances, i.e. which element is currently parsed.. Or use an existing one like HTML_Sax (can be found in the PEAR library).
If you ask yourself why it isn't possible with a regexp, google for the keywords "parser", "state machine", "fsm" and start reading...
De gustibus non est disputandum.
06-06-2005, 08:55 PM #3
Ah, thanks for the info, as I said, I know little of RegEx, well, time for some PHP coding