drxzpo70788179614 2015-02-24 23:16
浏览 42
已采纳

PHP:使用正则表达式在字符串中查找数组模式

I have a string like this it is array pattern :

["foo","bar","bra bra","xxx123"]

How can i get the foo,bar,bra bra,xxx123 Pattern is ["","",""]

  • 写回答

3条回答 默认 最新

  • dougan7523 2015-02-24 23:50
    关注

    You can do it without regex:

    $result = explode('","', trim($str, '[]"'));
    

    or with regex:

    if (preg_match_all('~"([^"]*)"~', $str, $m))
        $result = $m[1];
    

    or a regex to handle escaped quotes:

    if (preg_match_all('~"([^"\\\]*(?s:\\\.[^"\\\]*)*)"~', $str, $m))
        $result = $m[1];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?