Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: RegEx help

  1. #1
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts

    RegEx help

    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); 
    All my attempts have failed miserably, any help would be appreciated.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    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.

  • #3
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Ah, thanks for the info, as I said, I know little of RegEx, well, time for some PHP coding


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •