PHP regular does not contain a certain string sample code

WBOY
Release: 2016-07-25 08:52:46
Original
1333 people have browsed it
This article introduces how to write PHP regular expressions that do not contain a certain string. Examples of regular expressions that do not contain a specified string. Friends in need can refer to it.

In PHP programming, the common function for matching strings is strstr($str, “abc”); Regular matching

preg_match(”/(abc)?/is”, $str);

But if you want to match a string that does not contain a certain string, it is more troublesome to use regular expressions. The problem can be solved if the regular expression !strstr($str, “abc”); is not used.

Use regular names like this:

"/^((?!abc).)*$/is"

Example:

The result is: false, containing abc!

$str = "2b3c4d5c";

Note: [^(abc)] This syntax checks whether the characters in $str are not in a b c one by one.

preg_match(”/[^(abc)]/s”, $str, $arr);

The character 2 is not in a b c, so the return value of $arr is 2; Matches both the string "abc" and not the string "xyz"

"/(abc)[^((?!xyz).)*$]/s"


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!