I’m trying to write a regular expression in PHP. From this code I want to match ‘bar’.
<data info="foo">
"bar"|tr
</data>
I tried this two regex, without success. It matches ‘foo”> “bar’.
$regex = '/"(.*?)"\|tr/s';
$regex = '/"[^"]+(.*?)"\|tr/s';
Anyone can help me?
You need to escape the backslash in PHP strings:
I added a capturing group to get the contents of the quotes, which you seem to be interested in.
Since you seem to apply the regex to XML, I just want to warn you that XML and regular expressions don’t play well together. Regex is only recommendable in conjunction with a DOM.