http://www.perlmonks.org?node_id=891519

fbicknel has asked for the wisdom of the Perl Monks concerning the following question:

Fun stuff.

Say you have an oracle connect string that looks like:
['] [userid] [/ [password]] [@net_service_name] [']
Now say you want to parse that. I came up with this regex that seems to do it, at least for some of the simple tests below.

I humbly ask your opinions:
my ($userid, $password, $netServiceName) = /'?([^@\/']+)?(\/[^@\/']*)? +(@[^@\/']+)?'?/;
Samples.

>>string<< is parsed as <userid> </password> <@net_service_name>

Note, btw, the special case of '/' which needs to parse as simply '/'.
>>SYS/change_on_install@prod1<< <SYS> </change_on_install> <@prod1> >>rman/rman@rcat<< <rman> </rman> <@rcat> >>SYS<< <SYS> <> <> >>/<< <> </> <> >>/fooey<< <> </fooey> <> >>/fooey@foobar<< <> </fooey> <@foobar> >>SYS@foobar<< <SYS> <> <@foobar> >>'simple/fooey@foobar'<< <simple> </fooey> <@foobar>