s3gfault
s3gfault

Reputation: 35

Regex match 2 occurrence with no dots

Sample Text

23:00 VPN Tunnel Users by Bandwidth............

Daily Security Report

SSL-VPN Tunnel Users by Bandwidth........ Page 10 of 12

VPN Usage

Site-to-Site IPSec Tunnels by Bandwidth

#

Tunnel

No matching log data for this report

Client-to-Site IPSec Tunnels by Bandwidth

Duration

Traffic Out

Traffic In

IP

No matching log data for this report

SSL-VPN Tunnel Users by Bandwidth

#

1

User

user.z

134566

admin_ex

admin

user.b

user.a

IP

Final Report IP

Goal to parse

user.z

134566

admin_ex

admin

user.b

user.a

Current State of the solution

I have this regex : (?<=SSL-VPN Tunnel Users by Bandwidth).*?(?=IP) and works if there is no first occurrence of the SSL-VPN Tunnel Users by Banwidth string but when I have it on file the regex fail, is anyway to get only the second match ?

Upvotes: 1

Views: 86

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626747

You have 2 occurrences of SSL-VPN Tunnel Users by Bandwidth - one followed with dots and another with a linebreak.

Just add a line break to your lookahead:

(?<=SSL-VPN Tunnel Users by Bandwidth\n).*?(?=IP)
                                     ^^

See the regex demo

Or, use a negative lookahead failing the match if there is a dot after:

(?<=SSL-VPN Tunnel Users by Bandwidth)(?!\.).*?(?=IP)
                                      ^^^^^^

See another regex demo

If you can access submatches (groups), it is recommended to switch to a capturing group based regex:

^SSL-VPN Tunnel Users by Bandwidth\s+(.*?)\nIP$

See this regex demo

Upvotes: 1

Related Questions