【发布时间】:2017-08-20 19:36:20
【问题描述】:
标题几乎是不言自明的......
我的正则表达式仍然不完美,但在改进之前我需要解决 2 个问题...
我可以使用 ip:port 获取所有行,但我不知道如何:
- 删除该行内的其余文本。
- 在 THE SAME REGEX REQUEST 处将空行 \r\n\ 替换为空行。
那是一个文本文件的样本:
junk text junk text junk text junk text junk text junk text junk text
junk text 127.0.0.1:28 junk text junk text junk text junk text junk text
junk text junk text junk text junk 127.0.0.1:28text junk text
junk text junk text junk text 127.0.0.1:28 junk text
junk text junk text junk text
junk text 127.0.0.1:28 junk text
junk text
junk text 127.0.0.1:28 junk text
junk text 127.0.0.1:28 junk text junk text
junk text junk text junk text 127.0.0.1:28 junk text
junk text junk text junk text junk text junk text
junk text junk text junk text 127.0.0.1:28 junk text junk text junk text
junk text junk text 127.0.0.1:28 junk text junk text junk text junk text junk text
我期待着回来:
127.0.0.1:28
127.0.0.1:28
127.0.0.1:28
127.0.0.1:28
127.0.0.1:28
127.0.0.1:28
127.0.0.1:28
127.0.0.1:28
127.0.0.1:28
显然,该示例使用相同的 ip:port 行,但我不希望它是固定值。
是否可以通过 1 个单一的正则表达式请求来做到这一点?
...作为我尝试的起点:
^(?!.*[09].*).+$
【问题讨论】:
-
您可以尝试
(?s)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+)|(?:(?!\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+).)*并在Notepad++ 中替换为(?{1}$1\n:)。 -
我需要反过来做:\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0- 9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9 ]?):\d{1,5}\b
-
您可以使用自己的 IP 正则表达式模式代替
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+。技术是一样的。