[ 
https://issues.apache.org/jira/browse/NIFI-1919?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15301074#comment-15301074
 ] 

Andy LoPresto commented on NIFI-1919:
-------------------------------------

The issue was originally posted in the mailing list [1] and after more 
investigation [2] I think the solution is to add a new expression language 
method called replaceFirst, which parallels Java's String#replaceFirst [3] and 
accepts a regular expression pattern and replaces it only once. I will update 
the unit tests to properly capture this, and will update the documentation to 
reflect the new method. 

[1] 
http://apache-nifi-developer-list.39713.n7.nabble.com/Apache-NiFi-expression-language-td10610.html
[2] 
http://apache-nifi-developer-list.39713.n7.nabble.com/discuss-Proposed-addition-of-replaceRegex-to-expression-language-td10713.html

> Expression Language only evaluates regular expression replacement on 
> replaceAll, not replace
> --------------------------------------------------------------------------------------------
>
>                 Key: NIFI-1919
>                 URL: https://issues.apache.org/jira/browse/NIFI-1919
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Core Framework
>    Affects Versions: 0.6.1
>            Reporter: Andy LoPresto
>            Assignee: Andy LoPresto
>             Fix For: 1.0.0, 0.7.0
>
>
> When {{${attribute:replaceAll('\w+', 'replacement')}}} is called, the pattern 
> is matched and applied. However, when {{${attribute:replace('\w+', 
> 'replacement')}}} is called, it is not. I believe this is because 
> {{ReplaceAllEvaluator}} uses {{String#replaceAll(String regex, String 
> replacement)}} while {{ReplaceEvaluator}} uses {{String#replace(CharSequence 
> target, CharSequence replacement)}} which then uses 
> {{Pattern.compile(target.toString(), Pattern.LITERAL)}} instead of compiling 
> for a regular expression. I am writing a unit test to demonstrate this and 
> show the results when {{String#replaceFirst()}} is used instead. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to