pelican_george pelican_george - 1 year ago 102
Javascript Question

Javascript REGEX to match multiple custom tags (also incomplete)

I'm trying to match "custom" tags that might be complete/incomplete as described below.

The bold text is what I'm trying to match.

  1. %end{some text

  2. %start{some text

  3. %start{some text}%end

  4. %start{some text}%end%start{more text}%end

Also, these tags can appear multiple times within a string. For example, the regex:


applied on the 4th example would capture:
%start{some text}%end%start{more text}%end

How would I go on about tho achieve the matches described on the first 4 examples?

Answer Source

With a lookbehind :


With the content in the first group :


You may need to add \r and \n to the negated character classes if you handle the data multiple lines at a time, as in my regex101 tests (lookbehind, first group).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download