dpjtn48868 2014-03-11 09:52
浏览 58

Php preg_match只捕获特定的短语

Example string:

$string = 'text text text text {capture this1, this2} text text text text';

I want to use preg_match, to get only these this1, and this2 in an array and nothing else.

I was trying something like so:

$array = array();
$reg = '/\{capture.*\}/'; //this needs changing
preg_match($reg, $string, $array);
var_dump($array);

This captures {capture this1, this2}. How do i exclude the '{' sign from regex? I was trying something like .!\{ but it gave me errors. Any suggestions?

  • 写回答

2条回答 默认 最新

  • doulan9287 2014-03-11 09:54
    关注

    You can try with following regex:

    /\{(capture[^}]*)\}/
    
    评论

报告相同问题?