正则表达式“替换所有但"记事本++ v6.3 [英] RegEx "replace all but" for Notepad++ v6.3

查看:41
本文介绍了正则表达式“替换所有但"记事本++ v6.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一次接触正则表达式和记事本++,相对缺乏经验.我想要做的是替换这两个防火墙会话中除策略编号之外的所有内容.请注意,我有一个列表,多个列表长达 700 多行,所以我想一次性替换所有内容,只留下每一行的保单编号.

First timer and relatively inexperienced with RegEx and Notepad++. What I am trying to do is replace everything but the policy numbers in these two firewall session. Mind you, I have a list multiple lists 700+ lines long so I want to replace everything in one pass, leaving just the policy number for each line.

id 1978781/s23,vsys 0,flag 00200440/4000/0003,policy 4332,time 5972, dip 0 module 0
id 1997645/s23,vsys 0,flag 00200440/4000/0003,policy 30562,time 6283, dip 0 module 0

有成千上万种不同的保单号码,因此简单的搜索是行不通的.

There are thousands of different policy numbers, so a simple search wont do.

我希望我的线条在替换后看起来像这样.

I would like my lines to look like this after a replace.

4332
30562

针对这个问题尝试学习 RegEx 两个小时后,我意识到它比我预期的要复杂得多,我需要花时间学习它,因为它是一个非常强大的工具.这真的可以节省很多时间,不幸的是我目前没有.我期待更多地了解 RegEx,并感谢您能给我的任何帮助或指导.

After two hours of trying to learn RegEx for this one problem, I realized this its more involved than I expected, and I need to spend time learning this since its a very powerful tool. This could really save a lot of time, which unfortunately I don't have at the moment. I'm looking forward to learning more about RegEx and appreciate any help or direction you could give me.

推荐答案

鉴于行看起来总是一样的,您可以使用以下内容

Given the fact the lines always look the same you can use the following

^.+policy (\d+).+$

替换为:$1

点是一个通配符,所以 .+ 表示查找单词policy"之前的所有内容.然后找到一组数字(\d+ 用于查找数字)并保存它们(这就是许多正则表达式引擎中括号的用途).然后找到直到行尾的所有字符.

The dot is a wild card so , .+ means find everything before the word "policy ". Then find a group of digits (\d+ is for finding digits) and save them (thats what the parenthesis are for in many regex engines). Then find all the characters till the end of the line.

^ 字符表示行的开始.$ 表示行尾.

The ^ character means start of line. The $ means end of line.

这篇关于正则表达式“替换所有但"记事本++ v6.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆