Page 1 of 1

Help with Regular Expression

Posted: 31 Dec 2020 05:08
by shoshk
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

Re: Help with Regular Expression

Posted: 31 Dec 2020 06:54
by shoshk
I think I found the answer to my question. It seems that lua expressions do not include the 'or' operator. :(

Re: Help with Regular Expression

Posted: 31 Dec 2020 08:04
by ColeValleyGirl
It helps to remember that Lua patterns are not regexes. (It drives me mad too).

Re: Help with Regular Expression

Posted: 31 Dec 2020 11:14
by tatewise
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.