use*_*938 2 php regex preg-match-all
我的代码如下:
preg_match_all(UNKNOWN, "I need \"this\" and 'this'", $matches)
Run Code Online (Sandbox Code Playgroud)
我需要REGEX $matches只返回两个没有引号的"this"条目.
我认为以下应该有效:
$str = 'I need "this" and \'this\'';
if (preg_match_all('~(["\'])([^"\']+)\1~', $str, $arr))
print_r($arr[2]);
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
Array
(
[0] => this
[1] => this
)
Run Code Online (Sandbox Code Playgroud)