I am trying to match the quoted strings within a piece of text and the quotes I also allow I tried this regular expression in an online examiner, and it works perfectly though, when I see it in preg_match_all, it fails on the first saving string.
Here is the code:
$ parStr = 'title = "My Little Website" year = "2007" Details = "with the original website ..." tech = "PHP, mySQL" link = "& lt; a href = \" http: //test.com \ "& gt; test.com & lt; / a & gt; ''; $ Matches = array (); Preg_match_all ('/ (\ w +) \ s * = \ s * "(([^ \\"] * (\\.)?) *) "/', $ ParStr, $ matches, PREG_SET_ORDER); // The match [4] [0] is' link = '& lt; a href = \ "'
This fails in the last match, only matches the first run out. When I try this but expression, it works perfectly.
The proper part of regex is:
"(([^ \\"] * (\\.) *) *) "
All lessons should be eaten for a quote or quotation from a surviving quote, after which eating alternative escape quote, from which the process is repeated twice or more, until one can not survive
Why will not it work in PHP? Why does not this work and how should it be decided?
I do not know why it is not working for a particular version of PHP, but using the idea of a non-greedy match, I came up with this string that works Is:
"(. *? [^ \\\])"
Unless it encounters any DBL quote, No exodus happens before four, till then it matches all the non-greed. For some strange reasons, three backslashes are necessary or an unmatched brand. Kate has a php complaint. I am thinking that its presence requires a backslash before the bracket, but I'm not sure. Can anyone confirm that why are the three backslashes necessary?
/ Edit the range of white space
No comments:
Post a Comment