You have to use delimiters when you are using the Perl Compatible Regular Expressions (PCRE) functions in PHP (to which preg_match()
belongs).
From the documentation:
When using the PCRE functions, it is required that the pattern is enclosed by delimiters. A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character.
The reason for using delimiters is that you can add pattern modifiers after the last delimiter, e.g. to make an case-insensitive match:
#[a-z]#i // # is the delimiter.
Back to your problem:
In your case, PHP thinks the brackets ()
are your delimiters (yes, opening and closing brackets are valid delimiters, see the documentation) and ?<=Open URN:
is your pattern . Then it encounters [
and treats it as pattern modifier, but it is not a valid one.
Your pattern with delimiter %
:
preg_match('%(?<=Open URN: )[0-9]+(?= LA:)%', 'Open URN: 100000 LA: ');
There are a lot examples in the documentation of preg_match()
Python vs PHP
The only thing I found regarding regular expressions in Python is, that Perl syntax is used but I don't know if the full syntax is supported.
As already mentioned, PHP uses PCRE. Description of the differences between PCRE and Perl regex.