- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个很大的电子表格,其中一些单元格可能包含多行文本,有的有编号,有的没有。我的目标是将这些单独编号的“项目”提取到单独的单元格中。
例如,输入单元格可能包含类似这样的内容(在“s”之间):
“1.甲方完成。
2./3.乙方按图纸 805/12 施工。
使用 ITP 675/24。
4.丙方拟订婚。”
请注意,项目编号从一行的开头开始,或者使用“/”跟在这样的后面。数字后面总是跟一个“.”。 (点)。点后面可能有一些空格或没有空格,然后项目的文本可能会分布在多行中。
在上述输入单元上运行,所需的输出将是:
单元格 1:“1。甲方完成。”
单元格 2:“2. B 方按照图纸 805/12 build 。
使用 ITP 675/24。”
单元格 3:“3. 乙方按照图纸 805/12 build 。
使用 ITP 675/24。”
单元格 4:“4. C 方参与。”
我一直在 VBA 中使用 RegExp 类对象,如下所示。这使我可以查明项目的开始,然后提取这些点之间的文本(或字符串的结尾):
Dim RegExObj1 As RegExp
Dim mc1 As MatchCollection
Set RegExObj1 = New RegExp
With RegExObj1
.Global = True
.IgnoreCase = True
.MultiLine = True
.Pattern = "(^|/)(\d+)\."
End With
Set mc1 = RegExObj1.Execute(CleanedCellText)
最佳答案
给定您的数据,像 (?:\d+\.\/)|(?:\d+\.[\s\S]+?(?=(?:\x0A+\d+\.)|$))
这样的模式将收集每行的开头(编号段)和行的其余部分(编号段)。
如果行号后跟./
, 它只收集这些,因此您可以通过测试最右边的字符是否为 /
来判断是否需要填写.在我们填充结果数组后,我们从下到上循环遍历它并决定我们需要在哪里填充空白。
所以这是另一种方法,使用正则表达式。
如所写,该公式返回一个垂直数组。如果您有带有动态数组的 O365,它将溢出结果。如果不这样做,您可以通过将公式作为数组公式输入多个单元格或使用索引函数来检索它们
Option Explicit
Function foo(s) As String()
Dim RE As RegExp, MC As MatchCollection, M As Match
Const sPat As String = "(?:\d+\.\/)|(?:\d+\.[\s\S]+?(?=(?:\x0A+\d+\.)|$))"
Dim sTemp() As String, I As Long
Set RE = New RegExp
With RE
.Global = True
.MultiLine = False
.Pattern = sPat
If .Test(s) = True Then
Set MC = .Execute(s)
ReDim sTemp(1 To MC.Count, 1 To 1) '2D array for vertical results
I = 0
For Each M In MC
I = I + 1
sTemp(I, 1) = M
Next M
End If
For I = UBound(sTemp, 1) - 1 To LBound(sTemp, 1) Step -1
If Right(sTemp(I, 1), 1) = "/" Then
sTemp(I, 1) = Replace(sTemp(I, 1), "/", "") & Mid(sTemp(I + 1, 1), InStr(sTemp(I + 1, 1), ".") + 1, 999)
End If
Next I
foo = sTemp
End With
End Function
(?:\d+\.\/)|(?:\d+\.[\s\S]+?(?=(?:\x0A+\d+\.)|$))
选项:^$ 在换行符处不匹配
(?:\d+\.\/)
(?:\d+\.\/)
\d+
+
\.
\/
(?:\d+\.[\s\S]+?(?=(?:\x0A+\d+\.)|$))
(?:\d+\.[\s\S]+?(?=(?:\x0A+\d+\.)|$))
\d+
+
\.
[\s\S]+?
+?
\s
\S
(?=(?:\x0A+\d+\.)|$)
(?:\x0A+\d+\.)
(?:\x0A+\d+\.)
\x0A+
+
\d+
+
\.
$
$
关于regex - 是否可以改进此正则表达式以在 Excel 单元格中查找编号的文本行以避免错误匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61872398/
我使用 Faker gem 来播种某些数据。我怎样才能设置最大。假公司名称的长度,如何设置假号码的范围? name = Faker::Company.name 这里我想包括最大长度,因为名称对最大长
我试图实现一种方法,在该方法中我创建一个记分板(while 循环)并按某个数字字段(点)对获取的结果进行排序。但我需要实现的是如下 rank----username--point 1st------t
如何在 ListView (vsReport) 中对项目进行编号?现在我有类似的东西: Item := ListView1.Items.Add; Item.Caption :=inttostr(Ite
我正在尝试使用几个按钮在红色和绿色之间切换,我已经浏览了 Jquery 文档,但我似乎无法弄清楚这个。 您可以在我的代码片段中看到,当我单击按钮时,所有按钮都会变成不同的颜色。 而且必须有一种更短的方
是否可以在 GROUP_CONCAT 中进行编号 喜欢 如果,来自 GROUP_CONCAT(empnam SEPARATOR ', ') 我有一套, 我需要 我试过跟随,但没有得到想要的结
在 Linux 中,如何使用用户指定的事件编号创建输入事件接口(interface)并将其映射到特定的设备事件? 我正在使用 gpio-keys 驱动程序来翻译键盘上的按键操作。我定义了要在我的板配置
对于低级应用程序,我在编译时将某种索引定义为一种类型: template class Idx{ using TYPE = T_; static const int IDX = IDX_; }
请问如何设置这种格式的编号: 1) number 1 2) number 2 3) ... 在 HTML 中? 我只找到了一种获取这种格式的方法: 1. number 1 2. number 2 3.
对于我的研究,我需要很少的数据,其中之一是前一次提交的 SHA 编号,即如果我提供特定的提交编号/SHA 编号,我应该能够获得它之前的 SHA 编号。 帮我用 git 命令来获得相同的结果。 最佳答案
我需要询问何时按下数字 1 键,而不是在数字键盘上,而是在 Q 上方的数字 1(试图使这尽可能清楚)。 我已经浏览了 Keys 数组上所有可用的键,但没有一个匹配我正在寻找的键。 有没有办法做到这一点
我正在尝试使用 NAnt 任务设置构建服务器。我有几个想要构建的 Git 存储库,但我在结果的版本控制方面遇到了问题。 如何对库 (dll) 进行版本控制,以便每个构建都使用一个数字来表示每个版本?我
我有一个如下所示的表格: +-------+--------+--------+ | Grp | Party | Member | +-------+--------+--------+ | F
我正在使用 SQL Server 2008。我在查询中返回了这些数据,看起来非常像按 Day 和 ManualOrder 排序的... ID Day ManualOrder Lat L
区域:Silverlight 中的文本框 问题:我需要知道当前编辑的是什么“行号”。 我试过:作为一种解决方法,我尝试使用 textBox.Split("\r") 进行拆分,并计算 Regex 上具有
提前致歉,我不确定如何将 null 值添加到 pandas 数据框,所以我在列表中放置了“无”。我有一个具有以下值的数据框: None, None, 50,60,70,80,90,None,None,
我的应用程序中有一个标签,其中会带有徽章编号,该标签基于3个不同时间发生的3种不同操作。我知道如何使用以下方式设置标签栏标志: [[[[[self tabBarController] tabBar]
有谁知道为什么我们的供应商需要我们的 sku 编号来开发新应用程序? 我们自己将应用程序带入应用程序商店,也许我错了,但构建应用程序或将其上传到商店不需要 sku - 它仅在 iTunes 中连接而不
这个问题已经有答案了: Rationale for Matcher throwing IllegalStateException when no 'matching' method is called
我使用[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]清除徽章编号。它工作正常,但同时删除了远程通知。 还有许多其
我有一个待办事项列表应用程序,我想在图标徽章中显示未完成任务的数量。 我的问题是:我是否应该在用户每次在应用程序中删除/添加新任务时更新徽章编号,还是仅在应用程序即将进入后台模式时更新徽章编号? 最佳
我是一名优秀的程序员,十分优秀!