Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Regex Problem

by FunkyMonk (Chancellor)
on Aug 01, 2007 at 18:00 UTC ( [id://630131]=note: print w/replies, xml ) Need Help??


in reply to Regex Problem

You can use a negated character class: [^-\w] (match any character that isn't a \w or dash):
if ( $dir =~ /[^-\w]/ ) { print "\t$dir is not clean.\n"; } else { print "\t$dir is clean.\n"; }#close if

See perlretut, perlrequick and perlre for the details.

Replies are listed 'Best First'.
Re^2: Regex Problem
by grinder (Bishop) on Aug 01, 2007 at 18:02 UTC

    That looks a little weird with the minus in the middle of the character class. Makes it look like a range. I'd sooner write that as

    if ( $dir =~ /[^\w-]/ ) {

    • another intruder with the mooring in the heart of the Perl

      I was (mistakenly) under the impression that a character class that ended with a dash was a syntax error, because perl treated it as though it were an unfinished range.

      After reading your post, I tried it in Perl, and of course it works fine. So, I thought it must be an AWKism, but no, it works there too.

      In short, I have no idea why I thought you couldn't end a character class with a dash. Lets just say it must be an age thing.

      Thanks for the enlightenment.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found