Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Regex to detect file name

by Anonymous Monk
on Jul 06, 2018 at 15:00 UTC ( [id://1218057]=note: print w/replies, xml ) Need Help??


in reply to Regex to detect file name

It's probably beating a dead horse at this point, but this looks like what you're trying to do, with explainations:

# original if($view_tag =~ m/[^A-Za-z0-9_\-\.]/) { # corrected if($view_tag =~ m/^[A-Za-z0-9][\w.-]*/) { # to anchor the match at the beginning, # the ^ comes immediately after the first /: m/^[A-Z ... # match the first character [A-Za-z0-9] # matching subsequent characters: [\w.-]* # \w is the same as [A-Za-z0-9_] # . does not need to be escaped when inside brackets # put - last inside brackets, otherwise it may indicate a range # the quantifier * matches 0 or more instances of the characters

Replies are listed 'Best First'.
Re^2: Regex to detect file name
by Laurent_R (Canon) on Jul 06, 2018 at 21:46 UTC
    # corrected if($view_tag =~ m/^[A-Za-z0-9][\w.-]*/) {
    I think that you need to add an end-of-string anchor at the end of the pattern to prevent matching if there are some unwanted or spurious characters after the last character matching [\w.-].

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 05:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found