This is a working regex:
/(ANSI|AAMVA) (\d{6})(\d{2})(\d{2})(\d{0,2})((?:DL)|(?:ID))+(.*?)\g{-2}+([^"]+)/
This is a sample string:
"@\n\nANSI 6334290212DL00389199ZO04420478DLDAQ3572928\nDAASMITH, JOHN DOE\nDAG\nDAL4389 NE 47TH AVE\nDAIASHLAND\nDAJOR\nDAK97555 \nDARC \nDASD \nDATM \nDAU504\nDAW180\nDBA12201212\nDBB19780303\n"
I am trying to match a delimiter, either DL
or ID
, that may be in the string a second time.
I want to match whichever of DL
or ID
matched previously.
The problem is, if I use ?
to accomplish this it stops being greedy and prefers 0 matches.
I'm stumped, am I missing something basic with how ?
operates?
Edit: The problem isn't extracting the JSON data, it's parsing the msg bit, using JSON doesn't do anything to accomplish this. I trimmed the string to just the pertinent part.
The fix by @hobbs works because it let's me change the ?
to a +
and still match nothing, if nothing is there.
Works! :)
/(ANSI|AAMVA) (\d{6})(\d{2})(\d{2})(\d{0,2})((?:DL)|(?:ID))+(.*?)(?:\g{-2}|(?="))+([^"]+)/