You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nifi.apache.org by idioma <co...@gmail.com> on 2016/05/20 21:25:49 UTC

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

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
<http://apache-nifi-developer-list.39713.n7.nabble.com/file/n10592/3c370620-54fb-4a38-b987-f87cc2f56493.template>  

inputJson.json
<http://apache-nifi-developer-list.39713.n7.nabble.com/file/n10592/inputJson.json>  

mapping_file.txt
<http://apache-nifi-developer-list.39713.n7.nabble.com/file/n10592/mapping_file.txt>  




--
View this message in context: http://apache-nifi-developer-list.39713.n7.nabble.com/Issues-with-Regex-used-with-ReplaceTextWithMapping-where-am-I-going-wrong-tp10592.html
Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.

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

Posted by idioma <co...@gmail.com>.
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. 



--
View this message in context: http://apache-nifi-developer-list.39713.n7.nabble.com/Issues-with-Regex-used-with-ReplaceTextWithMapping-where-am-I-going-wrong-tp10592p10598.html
Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.