[CLUE-Tech] Regular Expression in ViA

Timothy C. Klein teece at silverklein.net
Fri Mar 22 22:00:05 MST 2002


* Randy Arabie (randy at arabie.org) wrote:
> I'm having a brain cramp with regard to regular expressions in 
> vi.
> 
> I have a text file I'm preparing for an import into a db.  I need 
> to remove all the hypens from the phone numbers in one field.
> 
> I tried:
> 
> 	:%s/[0-9]-[0-9]//g
> 
> Which removed all of the hypens, AND all the numbers on either side :-(
> 
> I can't replace all hyphens, as there are some in other fields.  It is 
> safe to replace ANY hyphen BETWEEN two numbers.
> 
> If possible, please CC randyarabie at enecotech.com on any response.
> 

I always seem to make this same mistake.  Since the number on either
side was matched, it is also replaced.  Also, since you don't know in
advance what that number on either side is, you will need to save it
away in a pattern with \( and \) pairs.

So:
	:s%/\([0-0]\)-\([0-9]\)/\1\2/g

I think I got that right.  Regular expression are really good at looking
incredibly intimidating.

Tim

--
==============================================
== Timothy Klein || teece at silverklein.net   ==
== ---------------------------------------- ==
== "Hello, World" 17 Errors, 31 Warnings... ==
==============================================



More information about the clue-tech mailing list