Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Regex to detect file name

by Anonymous Monk
on Jul 05, 2018 at 20:36 UTC ( #1217998=note: print w/replies, xml ) Need Help??


in reply to Regex to detect file name

it is easy to do with two regexes, such as:
$f =~ /^[\w\.]+$/ && $f =~ /^\w/
The first checks what the entire filename consists of, and the second checks the leading letter. There are endless variations on the same idea.

Replies are listed 'Best First'.
Re^2: Regex to detect file name
by Laurent_R (Canon) on Jul 06, 2018 at 07:40 UTC
    it is easy to do with two regexes, such as: ...
    Easy, perhaps, but wrong. The suggested two regexes would match a string starting with an underscore.
    DB<1> $f = "_foo"; DB<2> print "Success" if $f =~ /^[\w\.]+$/ && $f =~ /^\w/; Success DB<3>
    Update (at 7:50 UTC): sorry, the last sentence below is wrong, I had missed the $ at the end of the first pattern.

    It would also accept garbage characters in the middle.

Re^2: Regex to detect file name
by Anonymous Monk on Jul 05, 2018 at 21:31 UTC
    thats a waste of resources
    /^\w[\w\.]*$/
      This is not a game of Name That Tune. There are no brownie-points for doing it in one regex versus two. If it does the job, is clear, and easy to maintain, Just Do It.

        As if we needed any further proof that you don't actually know how to think like an engineer.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2019-10-16 00:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?