Support Questions

Find answers, ask questions, and share your expertise

Using regular expression on flowfilename to update Attribute

avatar
Expert Contributor

Hello,

I am ingesting files with

names like

I_XXX_20171002024210_LU2016DKABCDE12345-2017-10-02-TESTDAC2-000003_xxxxxxx.json

I_SSSSS_20171003024653_US2016US3661159602CC8FC7-4963-4304-A211-D8BCDA152625_xxxxxxx.json

I want to update/set a flowfile attribute using regular expression on the filename

Is there a nifi expression language function that support that.

ie. ${filename:<regexec:()>}

This regular expression extract the date yyyymmdd in capture group #2 from the filename

\_([A-Za-z]{3,5})\_([0-9]{8}).*xxxxxxx.json
1 ACCEPTED SOLUTION

avatar
Master Guru

@Simon Jespersen

Can you once try using the below methods to change the filename

1.by using replaceAll string manupulation and adding the filename property as

${filename:replaceAll('.*\_([A-Za-z]{3,5})\_([0-9]{8}).*xxxxxxx.json','$2')}.json

40817-replaceall.png

2.another way is using getdelimited Manupulation

by adding filename property as

${filename:getDelimitedField(3, '_'):substring(0,8)}.json

40814-getdelimited.png

Both ways results the same output you can choose the best way which will fits for your case.

Output:-

40816-fn.png

View solution in original post

3 REPLIES 3

avatar
Master Guru

@Simon Jespersen

Can you once try using the below methods to change the filename

1.by using replaceAll string manupulation and adding the filename property as

${filename:replaceAll('.*\_([A-Za-z]{3,5})\_([0-9]{8}).*xxxxxxx.json','$2')}.json

40817-replaceall.png

2.another way is using getdelimited Manupulation

by adding filename property as

${filename:getDelimitedField(3, '_'):substring(0,8)}.json

40814-getdelimited.png

Both ways results the same output you can choose the best way which will fits for your case.

Output:-

40816-fn.png

avatar
Expert Contributor

@Shu Thank you so very much for that really good answer.

avatar

@Simon Jespersen

You can use UpdateAttribute and create a new attribute with the following EL : ${filename:getDelimitedField(3,'_')}

40818-screen-shot-2017-10-12-at-31354-pm.png