Issues with Regex used with ReplaceTextWithMapping: where am I going wrong?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Issues with Regex used with ReplaceTextWithMapping: where am I going wrong?

idioma
Hi,
I have come across an issue with my regex associated with ReplaceTextWithMapping. I have attached input and mapping files together with a NiFi template. My Json looks like this:

    {"field1": "someText",
      "field2": "Text Again",
      "field3": "Text Again"}

I am trying to match the first occurrence of a phrase starting with capital letter and having a space in between words (in my case "Text Again"). This is the regex I have ended up with:

("[A-Za-z]+\s[A-Za-z]+")

It should match the first "Text Again" as tested with the online tester https://regex101.com/ and replace that with the value from the mapping file:

"Text Again" "New Text"

However, it does not pick either and the substitution is not applied. Is my regex incorrect? Can you help?

Thank you so much for all your help,

I.

3c370620-54fb-4a38-b987-f87cc2f56493.template

inputJson.json

mapping_file.txt
Reply | Threaded
Open this post in threaded view
|

Re: Issues with Regex used with ReplaceTextWithMapping: where am I going wrong?

idioma
Hi all,
I went through a number tests until the moment when I have realised that the problem seems to be dealing with phrase sentences with spaces, e.g. "Text Again". Although the final version of my regex was still correct, as follows:

[A-Z][A-Za-z]*\s[A-Z][A-Za-z]*

The pattern was not picked, therefore the replacement did not occur.

I have then modified my input value and that in the mapping file to hold a "_" . The regular expression for the new pattern is:

"[A-Z][a-z]*_[A-Z][a-z]*"

and my mapping now looks like this:

"Text_Again" "New Text"

It now works because the input value coming from the Json file has an underscore, instead of \s. The replacement value can have as many spaces or special characters as you want, it does not matter. Can I run this by the community and find out whether this is a known limitation of ReplaceTextWithMapping?

Thank you so much,

I.