Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: One regex construct to handle multiple string types

by Krambambuli (Curate)
on Nov 29, 2008 at 10:19 UTC ( #726757=note: print w/replies, xml ) Need Help??


in reply to One regex construct to handle multiple string types

while(<DATA>) { /(.*\.)?(\S+)/; print "$2\n"; } __DATA__ 2L bar.2L bar.ber.bir. 2L bar.ber.bir.2L
works for me.

The above reads your request as "get the first substring part not containing whitespaces that follows the last dot char (if there is one) in the input string; otherwise, return the first substring part of the input string that doesn't contain whitespace".

Hope that helps.

Krambambuli
---

Replies are listed 'Best First'.
Re^2: One regex construct to handle multiple string types
by ikegami (Pope) on Nov 29, 2008 at 11:35 UTC
    /(.*\.)?(\S+)/

    has a needless capture

    /(?:.*\.)?(\S+)/

    And the .* is useless (OP didn't specify he wanted last possible match)

    /\.?(\S+)/

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://726757]
help
Chatterbox?
[stevieb]: I've finally added the ability for berrybrew to fetch the list of perls available directly from Strawberry's releases.json file. Instead of pulling from there on every single call, I've added a berrybrew fetch, so it's only updated..

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2017-03-31 01:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (364 votes). Check out past polls.