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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|