[Regular expression] how to & quot; match to end or end with a string & quot ;. for example, MV & amp; id17328895840 & amp; scm102 and MV & amp; id17328895840 can be matched. example: str & nbsp; MV & amp; id17328895840 & amp; scm102reg; & nbsp; & amp; [regular expression] ask how to "end or end a matching string ". for example, both MV & id = 17328895840 & scm = 102 and MV & id = 17328895840 can be matched.
Example:
Str = MV & id = 17328895840 & scm = 102
Reg = "/& id = (./) &/U ";
You can get 17328895840
However, MV & id = 17328895840 cannot be matched.
I tried reg = "/& id = (./) [& | $]/U ";
I want to teach you how to write regular expressions to match both of them at the same time.
Thank you.
------ Solution --------------------
$ Reg = "/& id = (. + )(? :&
------ Solution --------------------
$)/U ";
------ Solution --------------------
$ Reg = "/& id = (. + ?) (&
------ Solution --------------------
$ )/";