I want to apply string and a question mark. This works perfectly in javascript:
var re = / [? 7! 1] * $ /; Document.write ('lolwut'replace (again,'? ')); Replace Document.write ('lolwut?' (Again, '?')); Instead of the document.write ('lolwut ??' (again, '?')); Instead of the document.write ('lolwut ???' (again, '?')); Document.write ('lolwut ??? !!! 11'.rele (again,'? ')); All returned values are equal to "Lolut"? PHP version does not work as such:
$ re = '/ [? 7! 1] * $ / '; Echo preg_replace ($ re, '?', 'Lolwut') "\ N"; Echo preg_replace ($ re, '?', 'Lolwut?') "\ N"; Re: eGroup preg_replace ($ re, '?', 'Lolwut ??') "\ N"; Echo preg_replace ($ re, '?', 'Lolwut ???') "\ N"; Resonance preg_replace ($ re, '?', 'Lolwut ??? !!! 11') "\ N"; Output is:
lolwut? Lol wut ?? Lol wut ?? Lol wut ?? Lol wut ?? Am I doing wrong here?
Update:
$ (dollar) Br> One argument is that any letter that comes in or after the current match point does not actually consume it.
Thanks to salathe to provide a clue, the inherent global flag of Preg_replace. (You people should vote your answer, in fact)
Just to answer the question Asked ("What's wrong with me here? '), You are confused about that OK regular expressions match, with the given string, once again, regex In fact, it matches twice , which is why you get two question marks (two matches, two replacements). The root of R is a mixture of quantifiers ( * allows nothing to match) and end-anchor ( $ matches the end of the string). / P>
lolwut ??? !!! 11 :
- for regex first match
??? !!! 11 lulwut? - Still it matches the point at the end of the point
-
lulwut
If you want to continue using the same regex with , then preg_replace then the fourth ( $ limit ) for the argument 1 Value of Radaan by it limited to a replacement:
Preg_replace ( '/ [? 7! 1] * $ / ','? ',' Lolwut ??? !!! 111 ', 1); // Limit only one replacement ------------------ ^ For better solution, as with others Said, use.
Comments
Post a Comment