* Help with Lua Pattern for search and replace plugin

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
johnmorrisoniom
Megastar
Posts: 882
Joined: 18 Dec 2008 07:40
Family Historian: V7
Location: Isle of Man

Help with Lua Pattern for search and replace plugin

Post by johnmorrisoniom » 02 Mar 2017 22:42

I am going through my media and source name to rationalise them.
I have a several hundred of each in the format:

Census England Berwick On Tweed 1851 - HO107 piece 2421 folio 502 page 14

and I wish it to become

Census 1851 England Berwick On Tweed - HO107 piece 2421 folio 502 page 14

i.e. just move the year.

What should the pattern be please? I just can't get my head around these yet.
TIA
John

User avatar
tatewise
Megastar
Posts: 27088
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Help with Lua Pattern for search and replace plugin

Post by tatewise » 03 Mar 2017 13:30

Search: ^Census (.- )(%d%d%d%d )(%- .+)$

Replace: Census %2%1%3

That search should do it where :-
^Census is start of text anchor and match for Census
(.- ) captures the shortest text after Census up to a space and 4 digits
(%d%d%d%d ) captures 4 digits and a space
(%- .+) captures a non-magic hyphen, a space, and the remaining text
$ is end of text anchor
To get it to work reliably notice how each component except the last ends with a space character.

The replace is :-
Census followed by the 2nd, 1st, and 3rd captures.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
johnmorrisoniom
Megastar
Posts: 882
Joined: 18 Dec 2008 07:40
Family Historian: V7
Location: Isle of Man

Re: Help with Lua Pattern for search and replace plugin

Post by johnmorrisoniom » 03 Mar 2017 18:08

Brilliant Mike, Thanks very much.
Over 2000 replacements done in about 2 minutes.
I'll get the hang of lua patterns one day.
John

Post Reply