regex - 使用正则表达式从目录中提取数据

标签 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/

相关文章:

C# 正则表达式忽略尾随字符

Python 正则表达式 : Matching one named group or another

正则表达式匹配 D 或 E 后跟 2-3 位数字

r - 在 R 中使用正则表达式提取子字符串

javascript - Javascript 中的正则表达式没有它应该的那么贪婪?

python - 匹配字符直到到达某些字符的正则表达式是什么?

regex - Notepad++ 中的正则表达式,每行打开和关闭大括号

python - 字母之间具有恒定字母距离的正则表达式

ruby - 使用 =~ (正则表达式)尽可能向右匹配

从 R 中的 data.table 中删除十六进制值