My pattern works in JavaScript.
(?<=(?:username|Email|URL)(?:\s|:))[^\n]+
However, when I try to use it in PHP, I get this error:
A lookbehind assertion has to be fixed width
How I can fix it?
My pattern works in JavaScript.
(?<=(?:username|Email|URL)(?:\s|:))[^\n]+
However, when I try to use it in PHP, I get this error:
A lookbehind assertion has to be fixed width
How I can fix it?
M.Smith
On
Sadly, js does't have regexp lookbehide. This may help you solve this: javascript regex lookbehide alternative
Copyright © 2021 Jogjafile Inc.
Use a full string match restart (
\K) instead of the invalid variable-length lookbehind.Regex 101 Demo
Make the colon and space optional by trailing them with
?or*.Use
\V+to match the remaining non-vertical (such as\rand\n) characters excluding in the line.See the broader canonical: Variable-length lookbehind-assertion alternatives for regular expressions
To protect your script from falsely matching values instead of matching labels, notice the use
^with themmodifier. This will ensure that you are matching labels that occur at the start of a line.Without a start of line anchor,
Somethingelse: url whoopswill matchwhoops.To make multiple matches in PHP, the
gpattern modifier is not used. Instead, apply the pattern inpreg_match_all()