Reputation: 23
I'm trying to match the final occurrence of a pattern of WWNs like this:
addr: 10:00:00:00:c4:a2:42:15
port: 10:00:00:00:c4:a2:42:15
addr: 10:00:00:00:c4:a2:42:16
port: 10:00:00:00:c4:a2:42:16
When I tested this:
port: (([0-9a-f]{2}[:-]){7}([0-9a-f]{2}))(?!.*port: ([0-9a-f]{2}[:-]){7}([0-9a-f]{2}))
it matches only 10:00:00:00:c4:a2:42:15
. I thought my regex is non-greedy, but it looks like I'm still missing something.
Upvotes: 0
Views: 70
Reputation: 71538
.
doesn't match newlines. Try using [\s\S]
instead:
port: (([0-9a-f]{2}[:-]){7}([0-9a-f]{2}))(?![\s\S]*port: ([0-9a-f]{2}[:-]){7}([0-9a-f]{2}))
^^^^^^
Upvotes: 6