Regexp Help for \W less [.-_]

T

Trans

Regexp help. How do I write "all non-alphanumeric characets except .
(period) - (dash) and _ (underscore)"

Thanks,
T.
 
D

David A. Black

Hi --

Regexp help. How do I write "all non-alphanumeric characets except .
(period) - (dash) and _ (underscore)"

Just negate the things you don't want (with _ being subsumed in \w):

/[^\w.-]/


David
 
A

Ara.T.Howard

Regexp help. How do I write "all non-alphanumeric characets except .
(period) - (dash) and _ (underscore)"

re = %r/[^A-Za-z0-9._-]/

or depending on usage, you may want

re = %r/^\s*[^A-Za-z0-9._-]\s*$/

or something close

cheers.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 
D

David A. Black

Hi --

Regexp help. How do I write "all non-alphanumeric characets except .
(period) - (dash) and _ (underscore)"

re = %r/[^A-Za-z0-9._-]/

or depending on usage, you may want

re = %r/^\s*[^A-Za-z0-9._-]\s*$/

or something close

You get all that A-Za-z0-9_ stuff for the price of admission with \w
:)


David
 
T

Trans

David said:
Just negate the things you don't want (with _ being subsumed in \w):

/[^\w.-]/

Even better.

(I thought I tried that w/o success, but on reflection I may have
mistakenly used \W instead of \w.)

Thanks for the help,
T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top