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

Re: Complicated regexp problem

by Anonymous Monk
on Aug 02, 2017 at 17:24 UTC ( #1196573=note: print w/replies, xml ) Need Help??


in reply to Complicated regexp problem

(a-z_) should probably be ([a-z_]*), or better yet, (\w*).

You're asking for trouble by putting your pattern in a string before using it in a regex. To avoid multiple-quoting headaches, use qr like this:

my $regexp = qr{(?:ftp:\/\/)?\/{5}(a-z_)\/}; if ($link =~ /$regexp/) { ... }

Replies are listed 'Best First'.
Re^2: Complicated regexp problem
by johngg (Canon) on Aug 02, 2017 at 22:22 UTC

    No need to escape the slashes as you are not using them as delimiters.

    my $regexp = qr{(?:ftp://)?/{5}(a-z_)/};

    Cheers,

    JohnGG

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2023-02-07 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (40 votes). Check out past polls.

    Notices?