.net Net-使用正则表达式识别双引号之间的新行
我有以下字符串值:.net Net-使用正则表达式识别双引号之间的新行,.net,regex,vb.net,.net,Regex,Vb.net,我有以下字符串值: 1A-2A-3A-"Comment line 1 Comment line 2 Comment line A1 Comment line A2"-BREAK1 1B-2B-3B-"Comment line 3 Comment line 4"-BREAK2 1C-2C-3C-4C-BREAK3 1D-2D-3D-4D-BREAK4 我想在vb.net中使用一个正则表达式,它会给出以下结果: 1A-2A-3A-"Comment line 1|Comment line 2|Com
1A-2A-3A-"Comment line 1
Comment line 2
Comment line A1
Comment line A2"-BREAK1
1B-2B-3B-"Comment line 3
Comment line 4"-BREAK2
1C-2C-3C-4C-BREAK3
1D-2D-3D-4D-BREAK4
我想在vb.net中使用一个正则表达式,它会给出以下结果:
1A-2A-3A-"Comment line 1|Comment line 2|Comment line A1|Comment line A2"-BREAK1
1B-2B-3B-"Comment line 3|Comment line 4"-BREAK2
1C-2C-3C-4C-BREAK3
1D-2D-3D-4D-BREAK4
基本上规则是删除双引号之间的任何新行
欢迎任何帮助 我想出了下一个解决方案:
Dim vInput = <xml>1A-2A-3A-"Comment line 1
Comment line 2
Comment line A1
Comment line A2"-BREAK1
1B-2B-3B-"Comment line 3
Comment line 4"-BREAK2
1C-2C-3C-4C-BREAK3
1D-2D-3D-4D-BREAK4</xml>.Value
Dim vRegExMatch = System.Text.RegularExpressions.Regex.Matches(vInput, """[^""\\]*(?:\\.[^""\\]*)*""|'[^'\\]*(?:\\.[^'\\]*)*'")
Dim vSpecialChar As Char = "|" '"†"
For Each vMatch In vRegExMatch
vInput = vInput.Replace(CStr(vMatch.Value), CStr(vMatch.Value).Replace(vbLf, vSpecialChar))
Next
希望对某人有所帮助 正则表达式(以及任何其他类型的“小长度代码”方法)的基本要求是获得清晰的模式。您输入的模式是什么?删除包含“行”一词的行后的新行?另外,您可以发布您尝试过的内容吗?而且您的输入不会响应任何VB.NET接受的格式。我们能理解在第一个代码块中的每一行之后都有一个Environment.NewLine吗?@varocarbas当在双引号之间找到文本时,该模式会删除新行是的,在第二组示例中更清晰。在任何情况下,您都应该以VB可接受的格式提供它(并显示您的尝试)。现在你有了回答者,向他解释你的情况。
1A-2A-3A-"Comment line 1|Comment line 2|Comment line A1|Comment line A2"-BREAK1
1B-2B-3B-"Comment line 3|Comment line 4"-BREAK2
1C-2C-3C-4C-BREAK3
1D-2D-3D-4D-BREAK4