有人可以解释一下下面的表达方式
$input =~ m/\G".*?"(,|$)/gc || $input =~ m/\G[^,]*(,|$)/gc || die;
Run Code Online (Sandbox Code Playgroud)
这里有两个正则表达式.首先是:
\G # the end of the previous match
".*?" # something in quotes
(,|$) # and a comma, or the end of the string
Run Code Online (Sandbox Code Playgroud)
如果第一个失败,第二个将匹配:
\G # the end of the previous match
[^,]* # anything up to the next comma or end of string
(,|$) # and then a comma, or the end of the string
Run Code Online (Sandbox Code Playgroud)
我的猜测是两个正则表达式旨在匹配可以引用或不引用的东西,并且可以在逗号后面跟着更多的项目.
(c修饰符意味着如果匹配失败则保持当前位置,因此如果第一次失败,\G锚点将在第二次尝试匹配时不会改变.g修改器设置\G下一次匹配的位置- 除其他外.)
| 归档时间: |
|
| 查看次数: |
124 次 |
| 最近记录: |