Page 1 of 1

Problem with RegEx

Posted: Mon May 19, 2003 7:51 am
by mnb
I've got a list of names that I want to word swap. I have last name first, no comma in between, then first name. I did it this way to make alphabetizing it easy. What I want to do now is put the first name in front.

I've tried a zillion different Regular Expressions to get:
Jones Bob
Smith Mike

to change to:
Bob Jones
Mike Smith

but the mojo evades me. I've tried:
^\(\<.*\>\)\(?\)\(\<.*\>\)\n

^\(\[:word:]\)\(?\)\(\[:word:]\)\n


to use the replacement expression of \3\2\1\n
but I can't seem to get anything to work. I did get one or two combos that would work on the first couple of names, but after that it started garbling up names.

Any suggestions would be welcome.


Thanks!

figured it out...

Posted: Mon May 19, 2003 8:10 am
by mnb
Find: \(^[[:word:]]+\)\([[:space:]]+\)\([[:word:]]+\)$

Repalce: \3\2\1



works like a champ, start at top of file, click replace all, bam! Time to go to sleep! :D

Posted: Mon May 19, 2003 8:12 am
by MudGuard
Search for

Code: Select all

^\([^ ]+\) \([^ ]+\)$
replace by

Code: Select all

\2 \1
Explanation:

Code: Select all

^
start of line

Code: Select all

\(\)
remember stuff inside for replacement expression

Code: Select all

[^ ]
search for everything but a space

Code: Select all

+
at least one of whatever is before...

Code: Select all

$
end of line