I have a PCRE2 expression that reads a username from some logs. In the logs, the username might optionally be in brackets. I need to get the username via the regex, without the brackets of course.
Example logs:
msg_id="1100-0005" Authentication of Firewall user [someuser@somehost] from fe80::badd:cafe was rejected, password is incorrect
msg_id="5000-0001" WebUI User anotheruser@anotherhost from 10.0.0.2 log in attempt was rejected - invalid credentials.
The regex I came up with (where group 3 should be the username):
msg_id="[0-9a-fA-F]{4}-[0-9a-fA-F]{4}"\s(Authentication of)?\s?(.*\s[Uu]ser)\s\[?(\S+)\]?\s
So far, I get someuser@somehost] for the first log and anotheruser@anotherhost for the second log.
Is there a way I can get rid of the ending bracket without using non-greedy option ?