Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: RegEx Headaches

by bart (Canon)
on Jun 19, 2013 at 18:41 UTC ( #1039821=note: print w/replies, xml ) Need Help??


in reply to RegEx Headaches

You can do
@numbers = /(\d+)(?=\.)(?=.*\.xml$)/g
This uses lookahead, which will match the rest of the string, but not consume it.

If you don't need the extra check, you can just do

@numbers = /(\d+)/g

Replies are listed 'Best First'.
Re^2: RegEx Headaches
by oryx3 (Novice) on Jun 19, 2013 at 18:59 UTC

    Hmmm, interesting. Now I've got:

    DB<23> x $_ 0 'ActionLogs.1.2.3.4.5.6.7.8.9.xml' DB<24> x /(\d+\.)/g 0 1. 1 2. 2 3. 3 4. 4 5. 5 6. 6 7. 7 8. 8 9.

    but:

    DB<25> x /(\d+\.)+/g 0 9.

    Can anyone tell me why the quantifier makes it match only the last group?

      The quantifier actually makes it match every group; however, it only stores the last match in $1, and thus that's what you see in your return. See Extracting matches in perlretut.

      If you want to extract an arbitrary number of digits sandwiched between decimal points, you can grab them all, and then split the result.

      /((?:\d+\.)+)/g; split /(?<=\.)/, $1;
      Alternatively,
      [i]n list context, //g returns a list of matched groupings, or if there are no groupings, a list of matches to the whole regexp
      (see Global matching in perlretut) so you could try
      my @res = /(?<=\.)\d+\./g;

      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039821]
help
Chatterbox?
[ambrus]: Corion: the solution depends on who for. Some non-math presentations need to show lots of graphics or photos, with fine details and color. For those, blackboard or overhead transparencies aren't so good (yes, you can print on transparencies, but there's s
[ambrus]: ome quality limits), but film projection or computer projector is fine.
[ambrus]: A minority of math presenters are traditional and don't want to operate a computer. For them, handwritten overhead transparencies and blackboard are fine.
[Corion]: BTW, has anybody seen the Microsoft Surface Studio thing live?
[ambrus]: Some will operate a computer, but want to operate crazy unusable android-like GUIs. For those, printed overhead transparencies or simple slide editors and maybe even tablets are fine.
[ambrus]: Some people like me are fine in learning how to use some custom user interface. For me, I might want to make some keyboard- controlled interactive live slide writer program, like I said in the hypothetical case when I have lots of years of free time for th
[Corion]: ambrus: Some of my math professors delegated TeX-ing of the exercises etc. to their secretaries :) But they all had very neat handwriting and good blackboard operation anyway ;)
[ambrus]: is.

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2017-09-26 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (293 votes). Check out past polls.

    Notices?