You need following negate rules:-
--1--^(?!-) is a negative look ahead assertion, ensures that string does not start with specified chars
--2--(?<!-)$ is a negative look behind assertion, ensures that string does not end with specified chars
假设您希望凝视不以“开始”开头并以“结束”字符串结尾:-
Your Pattern is :
$pattern = '/^(?!x)([a-z0-9]+)$(?
$pattern = '/^(?!start)([a-z0-9]+)$(?<!end)/';
$strArr = array('start-pattern-end','allpass','start-pattern','pattern-end');
foreach($strArr as $matstr){
preg_match($pattern,$matstr, $matches);
print_R( $matches);
}
This will output :allpass only as it doen't start with 'start' and end with 'end' patterns.