<分区>
考虑以下字符串,它是一个目录
Table of Content
Name abc ......... 20
Name fghkjkj kjkj . 31
Name.with.dot ..... 45
我想提取部分的名称 'Name abc
' 'Name fghkjkj kjkj
' 和 'Name.with.dot
'
我还没有找到实现该目标的正确正则表达式,有什么见解吗?
标签 regex
<分区>
考虑以下字符串,它是一个目录
Table of Content
Name abc ......... 20
Name fghkjkj kjkj . 31
Name.with.dot ..... 45
我想提取部分的名称 'Name abc
' 'Name fghkjkj kjkj
' 和 'Name.with.dot
'
我还没有找到实现该目标的正确正则表达式,有什么见解吗?
最佳答案
我认为以下应该可行:
^.*?(?= \.+ \d+$)
假设您正在逐行工作或启用了MULTILINE
模式。 positive lookahead assertion确保我们在一行中只有点和数字后立即结束匹配。
解释:
^ # Start of line
.*? # Match any number of characters, as few as possible
(?= # Look ahead to assert that the following matches from here:
[ ] # a space
\.+ # one or more dots
[ ] # a space
\d+ # a number
$ # End of line
) # End of lookahead
关于regex - 使用正则表达式从目录中提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17591296/