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

Re: Regular Expression Question

by swkronenfeld (Hermit)
on Jul 21, 2004 at 22:58 UTC ( #376403=note: print w/replies, xml ) Need Help??


in reply to Regular Expression Question

The . (dot) in your regular expression will match anything. You need to escape it, i.e.

$folder =~ /(\d{6}\.?\d{2}?\w?)/;


Also, this regular expression is matching for files which are of the form ######## (8 numbers without a dot), and files of the form ######a (6 numbers and the optional letter), as well as a few other forms that it sounds like you don't awnt to capture. Is the optional 2 digit number and letter dependent on whether there is a dot? If so, you are going to need a slightly more complex regular expression.

One last question, why do you even have the regular expression in there? Can't you use $folder instead of $1 without loss of generality? You aren't doing a conditional based on whether or not the regexp matches, so I assume all folders are meant to be replaced in...

Replies are listed 'Best First'.
Re^2: Regular Expression Question
by MistaMuShu (Beadle) on Jul 22, 2004 at 19:00 UTC
    Can't you use $folder instead of $1 without loss of generality?

    Well, initially I was thinking that since the actual folder names are ######.##a_files (think html folders) that I would find the first part of the name and save it in $1

    Now that I look at it again with your replies, I see that it'd be a lot easier if I just negated "_files" and did /(^_files)/

    That was silly of me to not escape the dot :( And I'll have to read a bit more on the lookahead find because ?: still does not make perfect sense to me... Thanks!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2022-12-07 17:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?