I am trying to parse the three optional components of a string with this format any of these different combinations:
12345,abcd@ABCD -> $1=12345 $2=abcd $3=ABC
12345,abcd -> $1=12345 $2=abcd $3=empty
12345@ABCD -> $1=12345 $2=empty $3=ABC
12345 -> $1=12345 $2=emty $3=empty
Is it possible with a single regexp? I have done several attempts. When the string is complete no problem but the forms with parameters missing are escaping to me:
(.+),(.+)@(.+) // works when the string is complete
// but how do you express the optionality?
(.+),?(.+)@?(.+) // nope
(.*)[$,](.*)[$@](.*) // neither
(Another option, would be splitting the string into the components that looks quite trivial but I am curious about the regexp way)