php - Quantifier range not working in lookbehind -
okay i'm working on project need regex can match * followed 1-4 spaces or tabs , followed row of text. right i'm using .* after lookbehind testing purposes. can match explicitly 1, 2, or 4 spaces/tabs not 1-4. i'm testing against following block
* test line here * second test * third test * test
and these 2 patterns i'm testing (?<=(\*[ \t]{3})).*
works expected , matches 2nd line, same if replace 3 1, 2 or 4 if replace 1,4 forming following pattern (?<=(\*[ \t]{1,4})).*
no longer matches of rows , can't understand why. i've tried googling without success. i'm using g(lobal) flag.
php, many flavors, doesn't support variable length lookbehind. support alternation (|
) @ top level of lookbehind. ?
can break pattern. alternative use:
(?<=\*[ \t]|\*[ \t]{2}|\*[ \t]{3}|\*[ \t]{4}).*
or better, abort lookbehind group:
\*[ \t]{1,4}(.*)
this should work you, since doesn't seem have overlapping of matches anyway.
from manual:
the contents of lookbehind assertion restricted such strings matches must have fixed length. however, if there several alternatives, not have have same fixed length. (?<=bullock|donkey) permitted, (?<!dogs?|cats?) causes error @ compile time. branches match different length strings permitted @ top level of lookbehind assertion.
source: http://www.php.net/manual/en/regexp.reference.assertions.php
Comments
Post a Comment