Replace first comma of each line with a tab??

Find, replace, find in files, replace in files, regular expressions

Replace first comma of each line with a tab??

Postby jeanpaul » Fri Apr 21, 2006 4:53 pm

I'm new to this and trying to figure out a way to replace only the first comma of each line with a tab.

Last name, first name (tab)company name, Inc. (tab)position (optional)

I only want to delete the first comma because of the company name which may contain a second comma, as well as the position which sometimes contains a third comma. Also, the lastname may be two words separated by a space, or a hyphen.

Any ideas?


Thanks,

JP
User avatar
jeanpaul
Newbie
 
Posts: 2
Joined: Thu Apr 20, 2006 11:00 pm

Re: Replace first comma of each line with a tab??

Postby Mofi » Sat Apr 22, 2006 2:38 pm

Use this UltraEdit style regular expression. The help of UE about the Find command and regular expression should help you to understand it.

Find: %^([~,^r^n]+^),
Replace: ^1^t

% means start search at every begin of a line.

^(...^) a string found with the expression inside the brackets can be used again in the replace with ^1 (and ^2, ^3, ... up to 9 expressions are possible).

[~,^r^n] means NOT a ',' or line termination character (carriage return or linefeed).

+ means preceding expression or character one or more times.

So the whole search expression means:
Find a string at begin of a line which has at least 1 character and does not contain a comma or a line termination character. This string is marked for usage in the replace string too. After this string a comma must follow. The whole found string is replaced with the marked part - so the string from begin of the line to first comma does not change - and a tab character which replaces the comma.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4058
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Replace first comma of each line with a tab??

Postby jeanpaul » Fri May 05, 2006 1:39 am

Wow, Mofi... Thanks so much for your help!

Sorry it took me so long to get back here to reply... My hard drive and back up died simultaneously. My list cleaning problem quickly became the least of my worries (Ugh).
User avatar
jeanpaul
Newbie
 
Posts: 2
Joined: Thu Apr 20, 2006 11:00 pm


Return to Find/Replace/Regular Expressions