View Full Version : RegEx help
06-05-2005, 10:48 PM
I'm using the WP plugin Acronym Replacer (http://www.huddledmasses.org/), and I'm trying to make it ignore any acronyms inside <code> and <pre> elements. The default 2.8 code is:
$text = preg_replace("|(?!<[^<>]*?)(?<![?./&])\b$acronym\b(?!:)(?![^<>]*?>)|imsU","<acronym title=\"$description\">$acronym</acronym>" , $text);
All my attempts have failed miserably, any help would be appreciated.
06-06-2005, 12:19 PM
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... :)
06-06-2005, 09:55 PM
Ah, thanks for the info, as I said, I know little of RegEx, well, time for some PHP coding :p
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.