Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: requesting small regex

by BrowserUk (Pope)
on May 07, 2012 at 07:16 UTC ( #969196=note: print w/ replies, xml ) Need Help??


in reply to requesting small regex

As you probably know, \d+ matches digits. You want the opposite, which conveniently, perl provides as \D. (Note als: \s&\S; \w&\W; etc. ).

So:

print for split /\D+/, "13%22%3%43";; 13 22 3 43

Note: This applies to ASCII/ISO data; once you get into the world of Unicrap, you're on your own :(


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?


Comment on Re: requesting small regex
Download Code
Re^2: requesting small regex
by Anonymous Monk on May 07, 2012 at 07:21 UTC
    lol unicrap i shall remember that! :D p.s: also from uk.. nice wet country huh :(
      uk.. nice wet country huh :(

      Wet?! Were in the middle of a drought don't'ya know :)

      (Ya gotta love the optimism of the supermarkets advertising their barBQ stuff on TV :)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

Re^2: requesting small regex
by perl@1983 (Sexton) on May 07, 2012 at 07:28 UTC
    How about something like below? Apart from only digits, it also allows alphabets:
    perl -e '$a = "ab%13!3&z* Trial"; $a=~s/(\w+)\W+/$1/g; print $a;'
Re^2: requesting small regex
by thundergnat (Deacon) on May 07, 2012 at 18:11 UTC

    If you need to work with Unicrap, er.. Unicode, use Unicode named property assertions.

    print for split /\P{Alnum}+/, '&#945;&#946;&#950;#!&#1488;&#1513;<>!&# +1046;&#1048;&#1059;+sdfg.%12'; &#945;&#946;&#950; &#1488;&#1513; &#1046;&#1048;&#1059; sdfg 12

    Sigh. Imagine that those were not automatically converted to HTML codepoints.

      magine that those were not automatically converted to HTML codepoints.

      Posting (small) quantities of Unicrap is the one time (I think) that <pre></pre> tags are justified.

      I'm guessing that \P is 'not the named class'; and that {Alnum} is alpha-numeric. Is theRE no \P{Numeric}?


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        I'm guessing that \P is 'not the named class';

        Good guess

        and that {Alnum} is alpha-numeric. Is theRE no \P{Numeric}?

        Yes, but it is spelled \P{Digit}. perldoc perlre has details.

        Note: I am replying more for the OPs benefit then yours. I am fully aware that you know about perldoc perlre, and are likely a far better perl programmer than I.

        Cheers

        BTW the OP DID want to split on non-alphanumerics not just non-numerics. Ok, (s)he did say non-alphanomerics but... ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969196]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2014-07-28 05:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (186 votes), past polls