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?
Demo: https://regex101.com/r/x2W3S5/1
CodePudding user response:
Use a full string match restart (\K
) instead of the invalid variable-length lookbehind.
(?:username|Email|Url):? *\K[^\v]
Make the colon and space optional by trailing them with ?
or *
.
See also: Variable-length lookbehind-assertion alternatives for regular expressions
CodePudding user response:
Sadly, js does't have regexp lookbehide. This may help you solve this: javascript regex lookbehide alternative