There are many methods to determine whether a string contains another string:
1. Common functions
Strstr ($ STR, "ABC ");
2. Regular Expression matching
Preg_match ("/(ABC)/is", $ Str );
However, to match a string that does not contain a specific string, it is more difficult to use regular expressions.
1. Solve the problem without using the following regular expressions:
! Strstr ($ STR, "ABC ");
2. But use regular expressions.
Preg_match ("/^ ((?! ABC).) * $/is ", $ Str );
CompleteCodeExample
$ STR = "dfadfadf765577abc55fd ";
$ Pattern_url = "/^ ((?! ABC).) * $/is ";
If (preg_match ($ pattern_url, $ Str ))
{
Echo "does not include ABC! ";
}
Else
{
Echo "contains ABC! ";
}
Result: false, containing ABC!
The regular expression that contains the string "ABC" and does not contain the string "XYZ:
Preg_match ("/(ABC) [^ ((?! XYZ).) * $]/is ", $ Str );
This method is valid and is used as follows:
(? :(?! <\/Div>). | \ n )*? // Match a string that does not contain </div>
However, the final result shows that the method is extremely inefficient and can process very short texts (a dozen or dozens of words must match the same part of the regular expression) time can be considered for use, but when used for large spaceArticleThe time needed for resolution or multiple matching changes should not be used, and other methods should be used for replacement (for example, first parse the text that needs to match the regular expression of the paragraph, and then verify whether there is a paragraph in it ), regular expressions are not very effective when matching text segments without specific strings.