如何删除两个已知点之间的变量子串以外的所有文本?

时间:2017-06-29 22:02:17

标签: regex replace notepad++

我的VPN设备中有一个巨大的日志文件,我想将其缩减为Domain\Username。在Domain\Username之后有一些文本变体,但它都以日期(变化),时间(变化), - 访问 - DC - (一致),以及括号内的IP地址(括号保留但IP变化)开始。用户名长度也有所不同。任何帮助表示赞赏。

是的,我对RegEx很陌生......我正在使用Notepad ++来降低它。希望文本最后显示为Domain\username。我已经尝试了几个表达式来修剪它,但只是部分成功,因为Domain\Username之后的文本变化,所以留下了很多行。

实施例。 .*(?<=Username:)(?>,).*

示例数据:

2017-06-29 07:27:13 - Access-DC - [10.10.25.294] Domain\username(Basic Domain Access)[Basic Employee Access] - Web SSO: Authentication successful. Credential Used: Username: username, Error: (0) Initial, Realm: Domain.COM, Auth Type: (32) Kerberos, Cred Type: (0) System Credential, Target: server.Domain.com, Password: XXXXXX, Has Ticket: 1, Policy Auth: (32) Kerberos, Cred Label: Default, Server Realm: Domain.COM,

2017-06-29 07:27:13 - Access-DC - [10.5.27.236] Domain\username(Basic Domain Access)[Basic Employee Access] - Web SSO: Authentication successful. Credential Used: Username: username, Error: (0) Initial, Realm: Domain.COM, Auth Type: (32) Kerberos, Cred Type: (0) System Credential, Target: server.Domain.com, Password: XXXXXX, Has Ticket: 1, Policy Auth: (32) Kerberos, Cred Label: Default, Server Realm: Domain.COM,

2017-06-29 07:27:13 - Access-DC - [10.5.27.236] Domain\username(Basic Domain Access)[Basic Employee Access] - Web SSO: Authentication successful. Credential Used: Username: username, Error: (0) Initial, Realm: Domain.COM, Auth Type: (32) Kerberos, Cred Type: (0) System Credential, Target: server.Domain.com, Password: XXXXXX, Has Ticket: 1, Policy Auth: (32) Kerberos, Cred Label: Default, Server Realm: Domain.COM,

期望的输出:

Domain\username
Domain\username
Domain\username

1 个答案:

答案 0 :(得分:1)

定位](之间的子字符串,这样就可以实现:

模式:^[^]]+] ([^(]+).* 替换为:$1

Pattern Demo