Hi,
I'm having trouble figuring out a regex that should match the following source:
DN 132
CAND
CAND_GOOD ROMAN
NAME SETTINGS
DISPLAY_FMT FIRST,LAST
TYPE C50
TC 03221 01 051 131
^Ex1
-----------------------------------------------------
Ex2
DN 20133
TYPE L500
TN 03212 05 127 126
I would like the regex to match on:
(132)
(NAME) (SETTINGS)
(C50) in ex1.
And
(20133)
(L500) in ex2.
This means that NAME and SETTINGS should be captured only if they exist. So I figured this regex should work:
^DN {1,}(\d+)[\s\S]*?(?:^ {1,}(NAME) ([\w ]+))?[\s\S]*TYPE (\w+)
But the non-capturing group in the middle doesn't want to match it's subgroups when the ? is appended to it and I therefore only get (20133) (C50) in ex1. I would appreciate if someone could help me and explain this behavior.