note 103015 added to function.preg-match
| From: | MrBull at osu1 dot php dot net | Date: | Sun, 20 Mar 2011 15:32:57 +0000 |
| Subject: | note 103015 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-178030@lists.php.net to get a copy of this message | ||
Sometimes its useful to negate a string. The first method which comes to mind to do this is:
[^(string)] but this of course won't work. There is a solution, but it is not very well known.
This is the simple piece of code on how a negation of a string is done:
(?:(?!string).)
?: makes a subpattern (see http://www.php.net/manual/en/regexp.reference.subpatterns.php)
and ?! is a negative look ahead. You put the negative look ahead in front of the dot because you
want the regex engine to first check if there is an occurrence of the string you are negating. Only
if it is not there, you want to match an arbitrary character.
Hope this helps some ppl.
----
Server IP: 213.249.64.162
Probable Submitter: 83.117.87.253
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- https://master.php.net/note/edit/103015
Del: integrated -- https://master.php.net/note/delete/103015/integrated
Del: useless -- https://master.php.net/note/delete/103015/useless
Del: bad code -- https://master.php.net/note/delete/103015/bad+code
Del: spam -- https://master.php.net/note/delete/103015/spam
Del: non-english -- https://master.php.net/note/delete/103015/non-english
Del: in docs -- https://master.php.net/note/delete/103015/in+docs
Del: other reasons-- https://master.php.net/note/delete/103015
Reject -- https://master.php.net/note/reject/103015
Search -- https://master.php.net/manage/user-notes.php