输出前删除匹配字符

时间:2017-07-20 14:22:04

标签: c++ regex

我的正则表达式已经运作良好,但我想删除"输出中的字符。这可能与Regex一起使用吗?

正则表达方式: (?>\".*?\") 链接: https://regex101.com/r/G7OQ0a/2/

  

" SharedKeys" =" 0"," 1"," 2"," 3"," 4"," 5"" 6"" 7"" 8"" 9"
  " BroadCastKeys" =" 0"," 1"," 2"," 3"," 4"," 5"" 6"" 7"" 8"" 9"   " A"" B"" C"" d"" E"" F& #34;" G"" H"" I"" J"" K",& #34; L"" M"" N"" O"" P"" Q&# 34;," R"" S"" T"" U"" V"&# 34; W"" X"" Y"" Z"

     

" ProgramPath" =" D:\ Games \ WoW \ World of Warcraft \ Wow.exe"

匹配:" BroadCastKeys"或" L"等等

我的目标: BroadCastKeys或L等等

1 个答案:

答案 0 :(得分:1)

您可以使用此模式执行此操作:

(?!\G)"\K[^"]*

demo

想要跳过结束报价的位置(不用模式消费它)。要做到这一点(?!\G)禁止匹配是连续的。 (\G匹配上次成功匹配的位置或字符串的开头。)

请注意,如果您的字符串可能以双引号开头,则需要将模式更改为(?!\G(?!\A))"\K[^"]*以允许第一次匹配。

您还可以使其更简单并使用捕获组:

"([^"]*)"