* Help with Lua Pattern for Search and replace

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: 904
Joined: 18 Dec 2008 07:40
Family Historian: V7
Location: Isle of Man

Help with Lua Pattern for Search and replace

Post by johnmorrisoniom »

I have several hundred sources where I have text such as 014/015 in the title and publication info.
I want to change the publication info only to read 014 (loose the /015)

I have set the scope as flollows
image.png
image.png (48.37 KiB) Viewed 533 times
I have also tired the pattern

Code: Select all

%d%d%d/%d%d%d
and
image.png
image.png (76.73 KiB) Viewed 533 times
I have selected a small subset of records that I know contain the said text but get and error message

Code: Select all

[string "C:\ProgramData\Calico Pie\Family Historian\Pl..."]:3767: invalid use of '%' in replacement string
stack traceback:
	[C]: in function 'string.gsub'
	[string "C:\ProgramData\Calico Pie\Family Historian\Pl..."]:3767: in function 'DoSeekMatch'
	[string "C:\ProgramData\Calico Pie\Family Historian\Pl..."]:3865: in function 'DoAllItems'
	[string "C:\ProgramData\Calico Pie\Family Historian\Pl..."]:5231: in upvalue 'doPerformAction'
	[string "C:\ProgramData\Calico Pie\Family Historian\Pl..."]:5261: in function <[string "C:\ProgramData\Calico Pie\Family Historian\Pl..."]:5256>
	(...tail calls...)
	[C]: in function 'iuplua.MainLoop'
	[string "C:\ProgramData\Calico Pie\Family Historian\Pl..."]:2725: in field 'ShowDialogue'
	[string "C:\ProgramData\Calico Pie\Family Historian\Pl..."]:5398: in function 'GUI_MainDialogue'
	[string "C:\ProgramData\Calico Pie\Family Historian\Pl..."]:5414: in main chunk
What am I doing wrong?

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

Re: Help with Lua Pattern for Search and replace

Post by tatewise »

Hi John.
You need to include a bracketed capture in the Search to identify what you want kept.
Then in the Replace use %1 to identify the 1st capture is to replace the search text.
e.g.
Search: (%d%d%d)/%d%d%d
Replace: %1

See FHUG KB Understanding Lua Patterns that explains Captures.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
johnmorrisoniom
Megastar
Posts: 904
Joined: 18 Dec 2008 07:40
Family Historian: V7
Location: Isle of Man

Re: Help with Lua Pattern for Search and replace

Post by johnmorrisoniom »

Thank you Mike,
Worked perfectly

John
Post Reply