[CS-FSLUG] regexp help

Frank Bax fbax at sympatico.ca
Thu Nov 11 15:49:31 CST 2004


At 03:55 PM 11/11/04, Tim Young wrote:
>cat [myfile] | sed 's/([a-Z0-9][a-Z0-9]*)-([a-Z0-9][a-Z0-9]*)/\1--\2/g'

Isn't [a-Z0-9][a-Z0-9]* equivalent to [a-Z0-9]+

In Ed's original email you mentioned "or practically any ASCII char".  The 
above will work as long as the single character immediately preceeding 
*and* the single character immediately following the hypen are 
alphanumeric.  The regexp doesn't look at the rest of the word.

As soon as I typed that explanation, I realised Tim's regexp could use 
simply [a-Z0-9] instead of [a-Z0-9][a-Z0-9]*  (since the * can match zero 
characters, it isn't really doing anything in this case).

Frank 





More information about the Christiansource mailing list