Sami Sami - 3 months ago 9
PHP Question

Preg Match To Get Everything Between Total || and \\n|}

So I want to capture everything between

Total ||
and
\\n|}
inside a string. Right now my current code looks like this:

preg_match('/(Total ||)(.*?)(\\n)/', $jsonwiki, $competitors);


But my regex fails and returns an empty array and I have no idea why?

Answer

i dont know regular expressions well, i just added some escaping

(Total \|\|)(.*?)(\\\\n)

https://regex101.com/r/nF2wU5/1

| and \ escaped as they are used in the regular expression engine to mean particular things, so if you want a literal pipe you need \|

Comments