I have a long RE to match dates in multiple files and I would like to split it out over multiple lines so it is easier to read and update. I am setting it as a variable and then calling that variable in the regex statement.
set ::eval::regexdate { \d[\/\.-]\d{2}[\/\.-]\d{4}|\d{2}[\/\.-]\d{2}[\/\.-]\d{4}|\d{4}[\/\.-]\d{2}[\/\.-]\d{2}|(([12]\d|3[01])|([12]\d|3[01])(th|nd|rd|st))\s(January|February|March|April|May|June|July|August|September|October|November|December)\s\d{4}|(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)[\/\.-]\d{2}[\/\.-]\d{4} }
I am then calling it with the following regexp line...
if {[regexp "($::eval::regexdate)" $linefromfile all date]} {
Do something...
}
This all works fine if the RE is set as one long string, but if I try to break it out over multiple lines using (?x) as outlined in this post.
regexp pattern across multiple lines
set ::eval::regexdate {(?x)
\d[\/\.-]\d{2}[\/\.-]\d{4}|
\d{2}[\/\.-]\d{2}[\/\.-]\d{4}|
\d{4}[\/\.-]\d{2}[\/\.-]\d{2}|
(([12]\d|3[01])|([12]\d|3[01])(th|nd|rd|st))\s(January|February|March|April|May|June|July|August|September|October|November|December)\s\d{4}|
(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)[\/\.-]\d{2}[\/\.-]\d{4}
}
I get the following error...
`couldn't compile regular expression pattern: quantifier operand invalid.`
I am not sure why this is happening, my understanding is that using (?x) ignores all white space and comments so it should just stitch the lines back together to create the one long RE, no? Are the "|" operands causing an issue in the way that I have split the RE up?
Any help would be greatly appreciated in figuring out why it won't work when using (?x).
Thanks