Correction: this is my code... else if ( candidate =~ /^(?:0?[1-9]|[12]\d|3[01])[\\\-\\\/]+(\d{2}|\d{1})[\\\-\\\/]+(\d{4}|\d{2})$/ ) {
log.error("BINGO!") matcher = candidate =~ /^(?:0?[1-9]|[12]\d|3[01])[\\\-\\\/]+(\d{2}|\d{1})[\\\-\\\/]+(\d{4}|\d{2})$/ matchedSubstring = matcher[0][0] log.error("Matcher: ${matcher.toString()}") log.error("Matched substring: ${matchedSubstring}") day = matchedSubstring[matcher[0][1]] month = matchedSubstring[matcher[0][2]] year = matcherSubstriong[matcher[0][3]] log.error("Day: ${day}") log.error("Month: ${month}") log.error("Year: ${year}") log.error("Length of Day: ${day.length()}") log.error("Length of Month: ${month.length()}") log.error("Length of Year: ${year.length()}") } I suspect I need to look at how I'm setting day, month, and year from matcher. The log output: 2023-07-09 16:04:47,406 ERROR [Timer-Driven Process Thread-10] o.a.nifi.processors.script.ExecuteScript ExecuteScript[id=33a5179c-1df4-128b-52be-aaa96b947012] Candidate: 06-14-2023 2023-07-09 16:04:47,406 ERROR [Timer-Driven Process Thread-10] o.a.nifi.processors.script.ExecuteScript ExecuteScript[id=33a5179c-1df4-128b-52be-aaa96b947012] BINGO! 2023-07-09 16:04:47,406 ERROR [Timer-Driven Process Thread-10] o.a.nifi.processors.script.ExecuteScript ExecuteScript[id=33a5179c-1df4-128b-52be-aaa96b947012] Matcher: java.util.regex.Matcher[pattern=^(?:0?[1-9]|[12]\d|3[01])[\\\-\\/]+(\d{2}|\d{1})[\\\-\\/]+(\d{4}|\d{2})$ region=0,10 lastmatch=06-14-2023] 2023-07-09 16:04:47,406 ERROR [Timer-Driven Process Thread-10] o.a.nifi.processors.script.ExecuteScript ExecuteScript[id=33a5179c-1df4-128b-52be-aaa96b947012] Matched substring: 06-14-2023 2023-07-09 16:04:47,406 ERROR [Timer-Driven Process Thread-10] o.a.nifi.processors.script.ExecuteScript ExecuteScript[id=33a5179c-1df4-128b-52be-aaa96b947012] Could not parse: 06-14-2023 On Sun, Jul 9, 2023 at 11:59 AM James McMahon <jsmcmah...@gmail.com> wrote: > Hello. I have a conditional clause in my Groovy script that attempts to > parse a date pattern of this form: 06-14-2023. It fails - I believe in the > matcher. > > I am running from a NiFi ExecuteScript processor. Here is my conditional: > > } else if ( candidate =~ > /^(?:0?[1-9]|[12]\d|3[01])[\\\-\\\/]+(\d{2}|\d{1})[\\\-\\\/]+(\d{4}|\d{2})$/ > ) { > > log.error("BINGO!") > > matcher = candidate =~ > /^(?:0?[1-9]|[12]\d|3[01])[\\\-\\\/]+(\d{2}|\d{1})[\\\-\\\/]+(\d{4}|\d{2})$/ > log.error("Matcher: ${matcher.toString()}") > log.error("Matched substring: ${matchedSubstring}") > day = matchedSubstring[matcher[0][1]] > month = matchedSubstring[matcher[0][2]] > year = matcherSubstriong[matcher[0][3]] > > log.error("Day: ${day}") > log.error("Month: ${month}") > log.error("Year: ${year}") > > log.error("Length of Day: ${day.length()}") > log.error("Length of Month: ${month.length()}") > log.error("Length of Year: ${year.length()}") > > } > > My log output tells me I make it into the conditional, but then I fail on > the matcher: > > 2023-07-09 15:52:23,547 ERROR [Timer-Driven Process Thread-2] > o.a.nifi.processors.script.ExecuteScript > ExecuteScript[id=33a5179c-1df4-128b-52be-aaa96b947012] Candidate: 06-14-2023 > 2023-07-09 15:52:23,547 ERROR [Timer-Driven Process Thread-2] > o.a.nifi.processors.script.ExecuteScript > ExecuteScript[id=33a5179c-1df4-128b-52be-aaa96b947012] BINGO! > 2023-07-09 15:52:23,547 ERROR [Timer-Driven Process Thread-2] > o.a.nifi.processors.script.ExecuteScript > ExecuteScript[id=33a5179c-1df4-128b-52be-aaa96b947012] Matcher: > java.util.regex.Matcher[pattern=^(?:0?[1-9]|[12]\d|3[01])[\\\-\\/]+(\d{2}|\d{1})[\\\-\\/]+(\d{4}|\d{2})$ > region=0,10 lastmatch=] > 2023-07-09 15:52:23,547 ERROR [Timer-Driven Process Thread-2] > o.a.nifi.processors.script.ExecuteScript > ExecuteScript[id=33a5179c-1df4-128b-52be-aaa96b947012] Matched substring: > *null* > 2023-07-09 15:52:23,547 ERROR [Timer-Driven Process Thread-2] > o.a.nifi.processors.script.ExecuteScript > ExecuteScript[id=33a5179c-1df4-128b-52be-aaa96b947012] Could not parse: > 06-14-2023 > > Can anyone help me get this matcher to work? > > Thanks in advance for any help. > > Jim >