Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

how to highlight capture groups (regardless of nesting level) within regex matches (in PHP)

Last post 10-21-2008, 7:37 PM by ddrudik. 0 replies.
Sort Posts: Previous Next
  •  10-21-2008, 7:37 PM 47466

    how to highlight capture groups (regardless of nesting level) within regex matches (in PHP)

    I now have the highlighting of capture groups (regardless of nesting level) functional at myregextester.com, thanks to the PHP code snippet by 'vapoorize' posted here:

    http://phpsnips.com/tempSnip.php?id=5

    Seems like a simple enough solution once I saw the code, yet didn't seem so simple when I was struggling with attempts to solve it previously.  Maybe this post will help someone else attempting the same.

    If you are curious about the modified highlighting code that I use at the site, here it is the relevant code:

    http://pastebin.com/f9bd03cb

    The version I use at the site combines each named capture group with the unnamed capture group that follows it.  In PHP when you name a capture group an unnamed capture group with the same contents is also created in the resulting array, regardless if you have any use for that unnamed capture group or not.


View as RSS news feed in XML