Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Regex to detect file name

by sundialsvc4 (Abbot)
on Jul 06, 2018 at 02:21 UTC ( #1218013=note: print w/replies, xml ) Need Help??


in reply to Regex to detect file name

Not to put too fine of a point on it here, but ... I, too, would favor “two regexes” because the OP stated the original requirement also in two naturally-separable parts:

  1. The string must be a valid filename.
  2. The string must begin with a \w character.
Now, thinking as I always do about how one day the source-code might need to be changed (and what sort of testing might then be required based on the nature of that change), a two-regex approach splits the problem along very-natural boundaries that match a human description of the objective.   A more “clever” approach might demand much more exhaustive future testing.

Replies are listed 'Best First'.
Re^2: Regex to detect file name
by Laurent_R (Canon) on Jul 06, 2018 at 07:48 UTC
    Except that a solution with two regexes is actually more difficult to do correctly (at least in this specific case) and more likely to be wrong. Here, a single pattern describing first what is allowed for the first character and then what is allowed for the rest of the string is more natural and definitely better.
Re^2: Regex to detect file name
by Anonymous Monk on Jul 06, 2018 at 07:08 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2019-12-06 01:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (154 votes). Check out past polls.

    Notices?