note 103014 deleted from reference.pcre.pattern.syntax by thiago

From: Date: Mon, 21 Mar 2011 14:08:46 +0000
Subject: note 103014 deleted from reference.pcre.pattern.syntax by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-178047@lists.php.net to get a copy of this message
Note Submitter: MrBull ---- 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.

« previous php.notes (#178047) next »