Reputation: 125
I am new to thymeleaf and recently I partially figured it out how to remove special characters from a string. Following code is working but I have to replace every single special character.
${#strings.toLowerCase(#strings.replace(#strings.replace(#strings.replace(name, '''','-'), '&',''),' ','-'))}
Is there any way around so that I can use a single regex expression to remove all special characters from a string using thymeleaf?
Upvotes: 4
Views: 3444
Reputation: 20487
Java String
s already have a method to replace w/regex: string.replaceAll('...', '...')
. In your case, You can simply do:
${#strings.toLowerCase(name.replaceAll('[^A-Za-z0-9\-]', ''))}
Upvotes: 5
Reputation:
Try use some code like this:
Regex regex1 = new Regex(@"[^A-Za-z0-9]");
strings.replace(name, "", regex1.match(name));
Good Luck!
Upvotes: 1