http://qs321.pair.com?node_id=1040291


in reply to RegEx Headaches

G'day oryx3,

Welcome to the monastery.

I see a number of solutions that appear to be more complicated than necessary.

You've provided two pieces of sample input with expected output for each. In both cases, either of these will achieve what you want:

/\.(\d+)/g /(\d+)\./g

Here's my test:

$ perl -Mstrict -Mwarnings -de 1 Loading DB routines from perl5db.pl version 1.39_09 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. main::(-e:1): 1 DB<1> $_ = 'ActionLogs.1.1998.xml' + DB<2> x /\.(\d+)/g + 0 1 1 1998 DB<3> x /(\d+)\./g + 0 1 1 1998 DB<4> $_ = 'ActionLogs.1.2.3.4.5.6.7.8.9.xml' + DB<5> x /\.(\d+)/g + 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 DB<6> x /(\d+)\./g + 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 DB<7> q

-- Ken