* Help with Regular Expression

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
avatar
shoshk
Famous
Posts: 242
Joined: 13 May 2015 16:28
Family Historian: V7
Location: Mitzpe Jericho, Israel

Help with Regular Expression

Post by shoshk » 31 Dec 2020 05:08

I'm parsing a GEDCOM file. I want to find lines beginning with '2 DATE' or '2 PLAC'. The following expression works:

Code: Select all

sLine:match("^2 DATE") or sLine:match("^2 PLAC)
I'd like to combine this into one expression. I tried this:

Code: Select all

sLine:match("^2 (DATE|PLAC)")
but it doesn't work. Can somebody help? I'm really bad at this regular expression stuff. :oops:

Thanks,
Shosh
Shosh Kalson

avatar
shoshk
Famous
Posts: 242
Joined: 13 May 2015 16:28
Family Historian: V7
Location: Mitzpe Jericho, Israel

Re: Help with Regular Expression

Post by shoshk » 31 Dec 2020 06:54

I think I found the answer to my question. It seems that lua expressions do not include the 'or' operator. :(
Shosh Kalson

User avatar
ColeValleyGirl
Megastar
Posts: 4853
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Help with Regular Expression

Post by ColeValleyGirl » 31 Dec 2020 08:04

It helps to remember that Lua patterns are not regexes. (It drives me mad too).

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

Re: Help with Regular Expression

Post by tatewise » 31 Dec 2020 11:14

The best you can achieve with an Lua Pattern is "^2 [DP][AL][TA][EC]"
Which matches DATE and PLAC and potentially other tags but there are no standard tags that start with DL or PA nor end with TC or EA so all is OK.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

Post Reply