I'm having trouble with this regex. (https://regex101.com/r/vQLlyY/1)
My pattern is working and is:
(?<=Property: )(.*?)(?= \(Contact)|(?<=Property: )(.*?)(?= - )
You'll see in the link that the property text is extracted in both these strings:
Property: This is the property (Contact - Warren)
Property: This is another property - Warren
In my code, this pattern is stored like this:
$this->rex["property"][2] = '/(?<=Property: )(.*?)(?= \(Contact)|(?<=Property: )(.*?)(?= - )/s'
Then, it is extracted like this:
foreach ($this->rex as $key => $value ) {
if (isset($value[$provider])) {
preg_match_all($value[$provider], $emailtext, $matches);
if (!empty($matches[1][0])) {
$emaildetails[$key] = trim(preg_replace("/\r|\n/", "", $matches[1][0]));
} else {
$emaildetails[$key] = "";
}
}
}
In this example, $provider = 2
My problem I'm sure is with the blackslash because I can't get this code to pickup the (Contact
part of the pattern where I need to escape the bracket. I know the code works because I have many other patterns in use. Also, this works for the property text if the pattern is stored like this:
$this->rex["property"][2] = '/(?<=Property: )(.*?)(?= - )/s
So, am I storing the pattern correctly with the escaped bracket, or is that even my problem? Thanks in advance!