This article introduces, with the PHP regular area with "ABC" beginning, and can not be "xyz" end of the string method, the need for a friend reference.
Requirements:
Use the PHP regular expression match to start with "ABC", but the end cannot contain the string "X", "Y", "Z".
Analytical:
ABC begins with a regular write: ^abc.
Start with ABC, followed by a string of strings
The general use of [^ ....] To deny it.
Since it is the negation of "X", "Y", "Z", it is [^xyz].
The complete regular expression is this:
^abc[^xyz]*$
The following is a full PHP example that uses this regular, as follows:
<?php$str = ' abcdef124f '; $search = '/^abc[^xyz]*$/'; if (Preg_match ($search, $str)) {echo $str. ' In accordance with <br/> ';} else {echo $str. ' does not conform to <br/> ';} Output abcdef124f conforms to $str = ' abcdef12x124 '; {preg_match ($search, $str) {echo $str. ' In accordance with <br/> ';} else {echo $str. ' does not conform to <br/> ';} Output abcdef12x124 does not conform to//edit by www.jbxue.com?>
PHP matches strings that start with "ABC" and Cannot End with "XYZ"