commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gary D. Gregory (Jira)" <j...@apache.org>
Subject [jira] [Commented] (TEXT-173) Pattern.replaceAll() replacement string extended to Java-like expression syntax
Date Sun, 06 Oct 2019 00:39:00 GMT

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

Gary D. Gregory commented on TEXT-173:
--------------------------------------

Hi [~aunkrig],

I am not sure we need yet-another expression language here, especially since we can use the
Java Scripting framework already withing Apache Commons Text through {{org.apache.commons.text.lookup.StringLookupFactory.scriptStringLookup()}}.
Apache Commons also provides two other scripting components: Commons JEXL and Commons BSF.

What are you trying to achieve that cannot be done through Commons JEXL, Commons BSF, or
the Java Scripting framework?

Gary

> Pattern.replaceAll() replacement string extended to Java-like expression syntax
> -------------------------------------------------------------------------------
>
>                 Key: TEXT-173
>                 URL: https://issues.apache.org/jira/browse/TEXT-173
>             Project: Commons Text
>          Issue Type: Improvement
>            Reporter: Arno Unkrig
>            Priority: Major
>
> I've developed a class that extends the {{Pattern.replaceAll()}} syntax from
> {{   "Hello $1 $2"}}
> to a simple, Java-like expression syntax, e.g.:
> {{   "m.group.toUpperCase()"}}
> Example client code:
> {{   // Parse the expression.}}
> {{   Expression expression = new ExpressionEvaluator(}}
> {{       "prefix", // <= This is "our" variable}}
> {{       "m"       // <= Also declare variable "m", which will automatically
be available}}
> {{   ).parse(}}
> {{       "prefix + new StringBuilder(m.group).reverse()"}}
> {{   );}}
> {{   // ...}}
> {{   // Create a match replacer with the actual variable values.}}
> {{   Function<Matcher, String> matchReplacer = ExpressionMatchReplacer.get(}}
> {{       expression,}}
> {{       Mappings.<String, Object>mapping("prefix", "pre-") // <= pass the
value for variable "prefix"}}
> {{   );}}
> {{   // Now use the match replacer to substitute regex matches.}}
> {{   Matcher matcher = ...;}}
> {{   System.out.println(PatternUtil.replaceSome(matcher, matchReplacer));}}
> Would that be a neat extension to {{text.commons.apache.org}}?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Mime
View raw message