Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: RegEx Headaches by kcott
in thread RegEx Headaches by oryx3

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-24 03:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found