不知何故,零宽度否定后视断言 - 不匹配 ") 如果前面有 \ - 不能按预期工作。
这就是我现在所拥有的:
text = <<EOT
h1=_("This is a test")
h2=_("This is a test \"quotes\"")
h3=_("This is a test (\"quotes\")")
EOT
text.scan(/_\("(.*?)(?<!\\)"\)/)
=> [["This is a test"], ["This is a test \"quotes\""], ["This is a test (\"quotes"]]
但结果应该是:
=> [["This is a test"], ["This is a test \"quotes\""], ["This is a test (\"quotes\")"]]
最后一场比赛是错误的。