Php 如何在preg“u match”all中生成正则表达式;及;
如何在preg_match_all“and”中生成正则表达式Php 如何在preg“u match”all中生成正则表达式;及;,php,regex,expression,preg-match-all,Php,Regex,Expression,Preg Match All,如何在preg_match_all“and”中生成正则表达式 /cork&瓶子/i不起作用这是我使用的方法: $string = 'The mouse to nibble the cork from the bottle russia king.'; preg_match_all("/^(?=.*(cork))(?=.*(bottle))/i", $string, $matches); print_r($matches); 输出: Array ( [0] => Array
/cork&瓶子/i
不起作用这是我使用的方法:
$string = 'The mouse to nibble the cork from the bottle russia king.';
preg_match_all("/^(?=.*(cork))(?=.*(bottle))/i", $string, $matches);
print_r($matches);
输出:
Array
(
[0] => Array
(
[0] =>
)
[1] => Array
(
[0] => cork
)
[2] => Array
(
[0] => bottle
)
)
/ : regex delimiter
^ : begining of line
(?= : start lookahead
.* : 0 or more any character
(\bcork\b) : capture group #1 that contains "cork" with word boundaries
) : end of look ahead
(?= : start lookahead
.* : 0 or more any character
(\bottle\b) : capture group #2 that contains "bottle" with word boundaries
) : end of look ahead
/i : regex delimiter, case insensitive
说明:
Array
(
[0] => Array
(
[0] =>
)
[1] => Array
(
[0] => cork
)
[2] => Array
(
[0] => bottle
)
)
/ : regex delimiter
^ : begining of line
(?= : start lookahead
.* : 0 or more any character
(\bcork\b) : capture group #1 that contains "cork" with word boundaries
) : end of look ahead
(?= : start lookahead
.* : 0 or more any character
(\bottle\b) : capture group #2 that contains "bottle" with word boundaries
) : end of look ahead
/i : regex delimiter, case insensitive
评估是否需要按指定的顺序进行,或者可以按任何顺序进行?