Excluding specific strings from a capture group.

A swapping-ground for Regular Expression syntax

Excluding specific strings from a capture group.

Postby callumm » Wed Nov 04, 2015 10:37 pm

So I'm trying to swap first name / last name in a large group of files, and the following expression works a treat

match: ^(.+) (.+).jpg
replace: \2, \1

Each of the JPG files is a person's name, and no matter how many names that person has, the last name gets put first, and the remaining names are appended with a comma. The only problem is when that person's name has some postnominal characters like Jr. or Sr.

How do I exclude something like Jr. and Sr. so the regex doesn't consider them to be a last name? I've tried using negative lookup this way, to no effect.

^(.+) (.+)(?!^Jr$).jpg
callumm
 
Posts: 1
Joined: Tue Nov 03, 2015 11:56 pm

Re: Excluding specific strings from a capture group.

Postby Admin » Wed Nov 04, 2015 11:42 pm

Hi, can you give us some examples of the file names you need to swap? thanks
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm


Return to Regular Expressions