【问题标题】:RegExp Get substring between tabs and include a special charRegEx 获取选项卡之间的子字符串并包含特殊字符
【发布时间】:2014-03-07 20:16:13
【问题描述】:

我在这里遇到了一个简单的正则表达式问题。 我想从特定字符串中检索使用以下规则完成的所有子字符串: 1. 值在 TAB 之间。 2. 还包括双引号。

我该怎么做?

我找到了获取 TAB 之间值的方法,但我不知道如何包含双引号验证。

'get the text from clipboard
Dim stringInClipboard As String = ClipboardGet()

Dim vRegExMatch As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(stringInClipboard, "\t[^\t\\]*(?:\\.[^\t\\]*)*\t")

例子:

{Tab} Comment 1 {Tab}
{Tab} Comment 2 {Tab}
{Tab} Long comment text.

some text
.
"<--Double quotes!!!
.
{Tab}
{Tab} Comment 4 {Tab}

基本上,我想检索:

Long comment text.   
some text
.
"<--Double quotes!!!
.

【问题讨论】:

  • 请澄清一下,它是用 \t 还是用 "" 包围的值,还是更像 \t"value"\t ?
  • \tnot all "matches\twill" occur\t

标签: c# .net regex vb.net


【解决方案1】:

试试这个:

(?s)\t(?=[^\t]*?").*?\t
  • (?s) 使点字符与新行匹配,您的示例包括。
  • \t 检查字符串是否以制表符开头
  • (?=[^\t]*?") 在遇到下一个选项卡之前先查看是否有任何双引号
  • .*\t 匹配所有字符直到下一个标签,如果前瞻成功

【讨论】:

【解决方案2】:

感谢@kabb,我找到了答案!

我修改了一点正则表达式:

(?s)\t(?=[^\t]*[""]+)[^\t]*[\t]{1}

这是现场测试: http://regex101.com/r/rM6hC3

【讨论】:

    猜你喜欢
    • 2016-05-05
    • 2020-08-26
    • 1970-01-01
    • 1970-01-01
    • 2013-03-16
    • 2015-06-24
    • 2020-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多