Using string regex to replace string

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using string regex to replace string

amrita
Trying to do something on these lines:

Say testString = "abcd/xyz/removeThis"

 I want the replace to return 'abcd' (replace /xyz/* till end of string to '')

This doesn't work. What might work?
<p th:text="${#strings.contains(testString, '/xyz/')} ?
                        ${#strings.replace(testString, '/xyz/*', '')}   :  ${testString}"></p>
Reply | Threaded
Open this post in threaded view
|

Re: Using string regex to replace string

Zemi
Administrator
Hello,

there is a replace method, take a look at it at
  http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#strings

It calls directly java.lang.String.replace method, so it does not use regular expressions.

Take also a look at multipleReplace at
  http://www.thymeleaf.org/apidocs/thymeleaf/2.1.4.RELEASE/org/thymeleaf/expression/Strings.html

Regards,
   Zemi

Reply | Threaded
Open this post in threaded view
|

Re: Using string regex to replace string

amrita
I have tried 'replace' method for strings. It appears to remove only exact strings, not regex/dynamic strings after a given static string.