Hi Ilaria,

I tried to implement what you were asking for in the expression language and I 
think I discovered a bug in our implementation, which I have reported as 
NIFI-1919 [1]. The expression language evaluation delegates to String 
replace/replaceAll for the respective EL functions, but the invocation of 
replace compiles a Pattern with Pattern.LITERAL, which means it does not 
evaluate the regular expression. ReplaceAll works as expected, but obviously if 
you only want to match on the first occurrence of your pattern, this will not 
work for you.

I have provided a unit test [2] which demonstrates this issue, and I will be 
working on it soon.

Until this fix is in, I think the ExecuteScript processor with a simple Groovy 
line invoking replaceFirst is your easiest option.

[1] https://issues.apache.org/jira/browse/NIFI-1919 
<https://issues.apache.org/jira/browse/NIFI-1919>
[2] 
https://github.com/alopresto/nifi/blob/NIFI-1919/nifi-commons/nifi-expression-language/src/test/groovy/org/apache/nifi/attribute/expression/language/QueryGroovyTest.groovy
 
<https://github.com/alopresto/nifi/blob/NIFI-1919/nifi-commons/nifi-expression-language/src/test/groovy/org/apache/nifi/attribute/expression/language/QueryGroovyTest.groovy>

Andy LoPresto
[email protected]
[email protected]
PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69

> On May 24, 2016, at 1:47 PM, Joe Percivall <[email protected]> 
> wrote:
> 
> Hello,
> 
> Is there a specific reason you want to do this within Expression Language and 
> not a Processor? You can use the ExtractTest processor and it will add 
> attributes for the first occurrence of the pattern in the content of a 
> FlowFile.
> 
> Joe
> 
> 
> - - - - - -
> Joseph Percivall
> linkedin.com/in/Percivall
> e: [email protected]
> 
> 
> 
> On Sunday, May 22, 2016 5:56 PM, idioma <[email protected]> wrote:
> 
> 
> 
> Hi,
> I am interested to understand whether in NiFi it is possible to write
> regular expressions that only match the first occurrence of a pattern. I do
> not seem to be able to make this work and wonder whether it is just
> something not possible at all. Here is an example of what I mean:
> 
> https://regex101.com/r/nF3lE2/2
> 
> Thank you
> 
> 
> 
> --
> View this message in context: 
> http://apache-nifi-developer-list.39713.n7.nabble.com/Apache-NiFi-expression-language-tp10610.html
> Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to