Trying to wrap my head around Regex capturing groups and having a little trouble.
I have some strings for which I want to capture groups for:
@msg=hello;name=test 1 // Groups: msg = hello, name = test, rest = 1
@msg=hi 2 // Groups: msg = hello, name = null, rest = 2
@name=tt 3 // Groups: msg = null, name = tt, rest = 3
I have the following regex:
msg=(?P<msg>[^;]+)?.*name=(?P<name>[^;]+)?\s(?P<rest>.*)
Which works fine for the first row, but not the second or third. Any idea how I can make it work for them too? I tried putting some ()? around the capturing groups to no avail:
// Below gets me weird results
(msg=(?P<msg>[^;]+)?)?.*(name=(?P<name>[^;]+)?)?\s((?P<rest>.*))?
Thanks.