【发布时间】:2021-11-08 21:40:09
【问题描述】:
我正在尝试为以下文本创建模式
not included
4680145876
some text some text ffgg
30905102511638
1
other text other text
no included
这是我的尝试
^\s*\d{6,10}(?:\n(?!\s*\d{1,}\n).*){5}
我将在 VBA 中使用这样的模式 要突出显示的预期输出(五行)
468049876
some text some text ffgg
30905102639638
1
other text other text
** 我在遇到问题时更新了问题 假设文本是这样的
not included
468041476
some text some text ffgg
31605102764638
1
other text other text
extra line
416524332
some text some text ffgg
30905103594638
1
other text other text
extra line
6354422
no included
这里我需要块来遵循顺序: 1- 6 到 12 位数字 2-然后一行中的一些文本 3- 数字等于 14 位 4- 1 到 3 位数字 5-文本(这是问题所在,因为该文本可能是两行而不是一行),我需要将该额外的行包含为一行 所以文本示例的输出
468049876
some text some text ffgg
30905103685638
1
other text other text extra line
和
416524332
some text some text ffgg
30905101497638
1
other text other text extra line
我的意思是文本将只包含两个块(每行五行)
-
我正在使用这样的代码:
With CreateObject("VBScript.RegExp") .Global = True: .MultiLine = True: .IgnoreCase = True .Pattern = sPattern If .Test(sInput) Then Set col = .Execute(sInput) For i = 0 To col.Count - 1 x = Split(col.Item(i), vbLf) cnt = cnt + 1 For j = LBound(x) To UBound(x) a(i + 1, j + 1) = Application.WorksheetFunction.Clean(Trim(x(j))) Next j Next i End If结束
现在,当循环匹配项时,我得到了超过五个项目的变量 x。我预计只会得到五件物品。 每场比赛的第二组如何单独领取?
【问题讨论】:
-
当您使用
(?:\n(?!\s*\d{1,}\n)时,您的模式不能跨越只有数字的匹配行,因此您将无法通过30905103300638