似乎无法弄清楚处理这一行文本的表达式:
'SOME_TEXT','EVEN_MORE_TEXT','EXPRESSION IS IN (''YES'',''NO'')'
对此分组
SOME_TEXT
EVEN_MORE_TEXT
EXPRESSION IS IN ('YES', 'NO')
....我宁愿有一个漂亮的正则表达式而不是像indexOf()等字符串函数来解决这个问题。
答案 0 :(得分:4)
正则表达式'([^']|'')++'
将匹配您感兴趣的部分,如此演示所示:
$text = "'SOME_TEXT','EVEN_MORE_TEXT','EXPRESSION IS IN (''YES'',''NO'')'";
preg_match_all("/'([^']|'')+'/", $text, $matches);
print_r($matches[0]);
打印:
Array
(
[0] => 'SOME_TEXT'
[1] => 'EVEN_MORE_TEXT'
[2] => 'EXPRESSION IS IN (''YES'',''NO'')'
)