Regex to match 2 or more words

后端 未结 3 480
孤城傲影
孤城傲影 2021-01-21 17:30

I have a regex that tries to match for 2 or more words, but it isn\'t working as it\'s suppose to. What am I doing wrong?

$string = \"i dont know , do you know?\         


        
3条回答
  •  故里飘歌
    2021-01-21 17:59

    This will match for string that contains exactly 2 words or more:

    /([a-zA-Z]+\s?\b){2,}/g you can go http://www.regexr.com/ and test it

    PHP:

    $string = "i dont know , do you know?";
    preg_match("/([a-zA-Z]+\s?\b){2,}/", $string, $match);
    
    echo "
    ";
    print_r($match);
    echo "
    ";

    Note: do not use the /g in the PHP code

提交回复
热议问题