You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by James McMahon <js...@gmail.com> on 2022/10/04 15:19:39 UTC

Expression language to handle a capture group

I have an incoming filename that includes the pattern
prefix20221004035958postfix. I need to convert that yMdHms to seconds since
the epic within that filename.

This is the expression I attempt to use, but it seems to choke on the
capture group reference:
filename         ${filename:replaceFirst('([0-9]{14})', '*$1*
:toDate("yyyyMMddHHmmss","UTC"):toNumber()'}

How do I get this to work, applying expression language functions to the
capture group?
Thanks.

Re: Expression language to handle a capture group

Posted by Clinton Boyda <cl...@gmail.com>.
I have a list of expression language tools:
https://regexr.com/ <https://regexr.com/> with PCRE mode
https://www.debuggex.com/ <https://www.debuggex.com/>
https://extendsclass.com/regex-tester.html <https://extendsclass.com/regex-tester.html>

but would love to know if there is a tool where a person could give sample input (like your filename) then simply trial and error test at the expression language until you got the output you desired in realtime.  Does this exist?


On Oct 4, 2022, at 9:19 AM, James McMahon <js...@gmail.com> wrote:

I have an incoming filename that includes the pattern prefix20221004035958postfix. I need to convert that yMdHms to seconds since the epic within that filename. 

This is the expression I attempt to use, but it seems to choke on the capture group reference:
filename         ${filename:replaceFirst('([0-9]{14})', '$1:toDate("yyyyMMddHHmmss","UTC"):toNumber()'}

How do I get this to work, applying expression language functions to the capture group?
Thanks.


Re: Expression language to handle a capture group

Posted by James McMahon <js...@gmail.com>.
I continue to dig in an effort to try and get this to work. Found this,
which made me hopeful:
https://stackoverflow.com/questions/62512560/how-to-use-regex-capturing-group-variable-in-nifi-expression-language
Essentially it says to wrap single quotes around the capture group
reference, which would get me to this:

filename         ${filename:replaceFirst('([0-9]{14})',
'*'$1'*:toDate("yyyyMMddHHmmss","UTC"):toNumber()'}


It does not like this either:
filename         ${filename:replaceFirst('([0-9]{14})',
'*${'$1'*:toDate("yyyyMMddHHmmss","UTC"):toNumber()}'}


Unfortunately it continues to choke. I don't think it likes the single
quotes in the second expression of the replaceFirst('....', '....') being
followed immediately by the single quote at the front of $1.

Jim

On Tue, Oct 4, 2022 at 11:19 AM James McMahon <js...@gmail.com> wrote:

> I have an incoming filename that includes the pattern
> prefix20221004035958postfix. I need to convert that yMdHms to seconds since
> the epic within that filename.
>
> This is the expression I attempt to use, but it seems to choke on the
> capture group reference:
> filename         ${filename:replaceFirst('([0-9]{14})', '*$1*
> :toDate("yyyyMMddHHmmss","UTC"):toNumber()'}
>
> How do I get this to work, applying expression language functions to the
> capture group?
> Thanks.
>