Forum Moderators: bakedjake

Message Too Old, No Replies

Simple Regex Problem

         

rfontaine

6:51 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



hi,

I am looking for a regular expression that changes everything that is not alpha-numeric into just a dash, and also eliminates two or more dashes that are side by side so that there is only on.

something like xyz$%--123 abc
becomes just xyz-12e-abc

How might this be done?

Thank you in advance,
Ron

coopster

7:14 pm on Jan 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



s/[^[:alnum:]]+-?¦--+/-/g

Don't forget to rekey the pipe symbol (¦) as the board breaks them.

rfontaine

7:19 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



Thank you very much Coopster! I'll give er a try :-)

billegal

8:08 pm on Jan 4, 2005 (gmt 0)

10+ Year Member



Just curious, will this work the same too:

s/[^[:alnum:]]+/-/g

Basically, do you need anything in the pattern after the first plus sign?

I have been using the one in my post and wonder if it could break in some instances.

coopster

8:34 pm on Jan 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member




Just curious, will this work the same too

Yes, and it is a better expression. I sped through the message and wrote the regex verbatim without thinking too much as I hammered it down. I should have taken more time to optimize. Thanks, billegal ;)