我想构建一个可以的正则表达式
如果在上面的顺序中在大海捞针中找到单词frankie
goes
和comes
,则返回TRUE。
试过这个,但没有回来。
$subject = ' <h1>Frankie goes to hollywood and then comes back </h1>';
$pattern = "/\ Frankie (.*?) goes (.*?) comes (.*?)/";
// this patterns aims to say, find frankie goes and comes in this order with at least one space in between them
$success = preg_match($pattern, $subject);
if ( $success ) :
echo 'bingo';
endif;
答案 0 :(得分:-1)
这是答案(只是帮助某人)
if (preg_match("/[ ]Frankie[ ][\s\S]*goes[ ][\s\S]*comes[ ]/", " Frankie goes to hollywood and then comes back ")) : // OK
echo '<h1>bingo on FRANKIE .... GOES .... COMES</h1>';
endif;
if (preg_match("/[ ]Frankie[ ][\s\S]*comes[ ][\s\S]*goes[ ]/", " Frankie goes to hollywood and then comes back ")) : // OK
else:
echo '<h1>NO bingo on FRANKIE .... COMES .... GOES</h1>';
endif;