You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by Mika Borner <ni...@my2ndhead.com> on 2017/04/12 16:40:24 UTC

ReplaceTextWithMapping how to regex

Hi all

I'm not sure I understand how the ReplaceTextWithMapping processor 
works. Let's say my flowfile content looks like:

     xyz key=value1 foo bar value1

My mapping file looks like:

     value1    replacementvalue1

     value2    replacementvalue2

I just want to replace the occurrence of "value1" only when it's 
perpended with "key=". Therefore I'm writing the Regex "key=(\S+)" and a 
"Matching Group" of 1.

This unfortunately doesn't work.

Can someone explain, what's wrong?

Thanks!

Mika>







Re: ReplaceTextWithMapping how to regex

Posted by Mika Borner <ni...@my2ndhead.com>.
No problem :-)

Ok, it works. And now I also understand how the regex is applied.

Thanks!

Mika>


On 04/12/2017 06:46 PM, Andy LoPresto wrote:
> Mika,
>
> Apologies, that autocorrected to “Mike”.
>
> Andy LoPresto
> alopresto@apache.org <ma...@apache.org>
> /alopresto.apache@gmail.com <ma...@gmail.com>/
> PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69
>
>> On Apr 12, 2017, at 9:46 AM, Andy LoPresto <alopresto@apache.org 
>> <ma...@apache.org>> wrote:
>>
>> Hi Mike,
>>
>> If you want to replace “value1” only when it is preceded by “key=“ 
>> and have the result be “key=replacementvalue1”, try this pair of 
>> configuration values:
>>
>> regex: (?<=key=)(\S+)
>> matching group: 1
>>
>> The (?<=…) construction is a lookbehind, so the provided sequence 
>> will only match if it follows this, but won’t capture it as part of 
>> the match.
>>
>> Andy LoPresto
>> alopresto@apache.org <ma...@apache.org>
>> /alopresto.apache@gmail.com <ma...@gmail.com>/
>> PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69
>>
>>> On Apr 12, 2017, at 9:40 AM, Mika Borner <nifi@my2ndhead.com 
>>> <ma...@my2ndhead.com>> wrote:
>>>
>>> Hi all
>>>
>>> I'm not sure I understand how the ReplaceTextWithMapping processor 
>>> works. Let's say my flowfile content looks like:
>>>
>>>    xyz key=value1 foo bar value1
>>>
>>> My mapping file looks like:
>>>
>>>    value1    replacementvalue1
>>>
>>>    value2    replacementvalue2
>>>
>>> I just want to replace the occurrence of "value1" only when it's 
>>> perpended with "key=". Therefore I'm writing the Regex "key=(\S+)" 
>>> and a "Matching Group" of 1.
>>>
>>> This unfortunately doesn't work.
>>>
>>> Can someone explain, what's wrong?
>>>
>>> Thanks!
>>>
>>> Mika>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>


Re: ReplaceTextWithMapping how to regex

Posted by Andy LoPresto <al...@apache.org>.
Mika,

Apologies, that autocorrected to “Mike”.

Andy LoPresto
alopresto@apache.org
alopresto.apache@gmail.com
PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69

> On Apr 12, 2017, at 9:46 AM, Andy LoPresto <al...@apache.org> wrote:
> 
> Hi Mike,
> 
> If you want to replace “value1” only when it is preceded by “key=“ and have the result be “key=replacementvalue1”, try this pair of configuration values:
> 
> regex: (?<=key=)(\S+)
> matching group: 1
> 
> The (?<=…) construction is a lookbehind, so the provided sequence will only match if it follows this, but won’t capture it as part of the match.
> 
> Andy LoPresto
> alopresto@apache.org <ma...@apache.org>
> alopresto.apache@gmail.com <ma...@gmail.com>
> PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69
> 
>> On Apr 12, 2017, at 9:40 AM, Mika Borner <nifi@my2ndhead.com <ma...@my2ndhead.com>> wrote:
>> 
>> Hi all
>> 
>> I'm not sure I understand how the ReplaceTextWithMapping processor works. Let's say my flowfile content looks like:
>> 
>>    xyz key=value1 foo bar value1
>> 
>> My mapping file looks like:
>> 
>>    value1    replacementvalue1
>> 
>>    value2    replacementvalue2
>> 
>> I just want to replace the occurrence of "value1" only when it's perpended with "key=". Therefore I'm writing the Regex "key=(\S+)" and a "Matching Group" of 1.
>> 
>> This unfortunately doesn't work.
>> 
>> Can someone explain, what's wrong?
>> 
>> Thanks!
>> 
>> Mika>
>> 
>> 
>> 
>> 
>> 
>> 
> 


Re: ReplaceTextWithMapping how to regex

Posted by Andy LoPresto <al...@apache.org>.
Hi Mike,

If you want to replace “value1” only when it is preceded by “key=“ and have the result be “key=replacementvalue1”, try this pair of configuration values:

regex: (?<=key=)(\S+)
matching group: 1

The (?<=…) construction is a lookbehind, so the provided sequence will only match if it follows this, but won’t capture it as part of the match.

Andy LoPresto
alopresto@apache.org
alopresto.apache@gmail.com
PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69

> On Apr 12, 2017, at 9:40 AM, Mika Borner <ni...@my2ndhead.com> wrote:
> 
> Hi all
> 
> I'm not sure I understand how the ReplaceTextWithMapping processor works. Let's say my flowfile content looks like:
> 
>    xyz key=value1 foo bar value1
> 
> My mapping file looks like:
> 
>    value1    replacementvalue1
> 
>    value2    replacementvalue2
> 
> I just want to replace the occurrence of "value1" only when it's perpended with "key=". Therefore I'm writing the Regex "key=(\S+)" and a "Matching Group" of 1.
> 
> This unfortunately doesn't work.
> 
> Can someone explain, what's wrong?
> 
> Thanks!
> 
> Mika>
> 
> 
> 
> 
> 
> 


Re: Aw: ReplaceTextWithMapping how to regex

Posted by Mika Borner <ni...@my2ndhead.com>.
Thanks, will take a look at it!


On 04/12/2017 06:43 PM, Uwe Geercken wrote:
> Hi,
> you might want to use the ExecuteRuleEngine processor I wrote. It 
> allows you to do very complex checks on the data and then also update it.
> In other scenarios the MergeTemplate processor might work as well.
> have a look at: https://github.com/uwegeercken/nifi_processors
> rgds,
> Uwe
> *Gesendet:* Mittwoch, 12. April 2017 um 18:40 Uhr
> *Von:* "Mika Borner" <ni...@my2ndhead.com>
> *An:* users@nifi.apache.org
> *Betreff:* ReplaceTextWithMapping how to regex
> Hi all
>
> I'm not sure I understand how the ReplaceTextWithMapping processor
> works. Let's say my flowfile content looks like:
>
> xyz key=value1 foo bar value1
>
> My mapping file looks like:
>
> value1 replacementvalue1
>
> value2 replacementvalue2
>
> I just want to replace the occurrence of "value1" only when it's
> perpended with "key=". Therefore I'm writing the Regex "key=(\S+)" and a
> "Matching Group" of 1.
>
> This unfortunately doesn't work.
>
> Can someone explain, what's wrong?
>
> Thanks!
>
> Mika>
>
>
>
>
>