我正在尝试创建一个匹配字符字符的正则表达式+用特定符号EG:引号括起来的白色字符。
EG:
one "two" three four "five six"
我的正则表达式应该匹配“两个”和“五个六”
我正在尝试/^(\"\w+\")/
和类似的但我无法做到。
如何找到包含在特定符号中的正则表达式?
答案 0 :(得分:0)
摆脱^
锚点。 ^
会将匹配限制在字符串的开头。此外,您无需转义双引号:\"
→"
。
将\w+
更改为.+?
或[^"]*
以匹配空格。
/(".*?")/
答案 1 :(得分:0)
试试这个:
$str = 'one " two test " three four "five" six';
preg_match_all('/"(?P<words>\s*\w+[\s\w\s]*)"/',$str,$match);
echo "<pre>";
print_r($match['words']);
答案 2 :(得分:-1)
regexp("/^[a-zA-Z0-9.\'\"]$/i",$variable_name)