Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: exact word match

by samarzone (Pilgrim)
on Dec 22, 2010 at 12:23 UTC ( #878496=note: print w/replies, xml ) Need Help??

in reply to exact word match

Square brackets are for matching individual characters. The regex you wrote will reject (because of ^) any word that has any of 'm', 'a', 's', 't', 'e', 'r', '|' .. and so on.

If you meant a valid database name except the names given in your regex you could have written

if($name =~ /^[a-z0-9_]$/i && $name !~ /^(?:master|model|dbccdb|sybsec +urity|sybsystemdb|sybsystemprocs|tempdb|DBA)$/) { print "allowed\n" } else { print "not allowed\n" }

Update: This can also be written in a single regex using negative look-ahead assertion as follows

if($name =~ /^(?!(master|model|dbccdb|sybsecurity|sybsystemdb|sybsyste +mprocs|tempdb|DBA)$)(^[a-z0-9_]+$)/i) { print "allowed\n" } else { print "not allowed\n" }

-- Regards - Samar

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://878496]
[moritz]: ovedpo15 "use lib" is only for .pm files
[moritz]: if you don't have .pm file, you might to use "require" or "do" with an absolute path
[ovedpo15]: I need to use FindBin thought. does FindBin finds only modules? or it can find perl script also?
[moritz]: maybe you should start looking at the documentation of FindBin?

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2018-03-17 20:51 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (226 votes). Check out past polls.