【发布时间】:2010-02-01 06:18:55
【问题描述】:
假设需要被正则表达式捕获的部分由以下字符串中的PORTION指示
,"PORTION","","a",["some_string"]
PORTION 的例子是
- \"abc123
- abc123\"
- \"abc123\"
- abc\"123\"
- abc123
所以字符串实际上看起来像
- ,"\"abc123","","a",["some_string"]
- ,"abc123\" ","","a",["some_string"]
- "\"abc123\"","","a",["some_string"]
- "abc\"123\"","","a",["some_string"]
- "abc123","","a",["some_string"]
PORTION 用双引号括起来。 PORTION 中的双引号用反斜杠转义。我目前的模式是
my $pattern = '(.?([\\"]|[^"][^,][^"])*)';
上面例子的结果如下
- \"abc123","","a"
- abc123
- \"abc12
- abc\"123\""
- abc123"
该模式尝试匹配序列前面不是“,”的所有内容
并且还允许捕获 \"
但它没有按预期工作。
我怎样才能让它发挥作用?
【问题讨论】: