Problem with RegEx

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
mnb
Posts: 2
Joined: Mon May 19, 2003 7:47 am

Problem with RegEx

Post 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!
mnb
Posts: 2
Joined: Mon May 19, 2003 7:47 am

figured it out...

Post 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
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post 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
Post Reply