Groovy web console

subscribe to the feed Subscribe
to this
site

Remove set of characters from String using regex

Published 3 months ago by Mak with tags regex matches replaceAll
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
String request="http://localhost:8080/providerReviews?from=Provider&providerId=170&lang=fr"
println request
String langRegex="(.*)&lang=[a-z]{2}(.*)"
if(request.matches(langRegex))
{
request= request.replaceAll('&lang=[a-z]{2}','')
println "Matched"
}else
println "Not Matched"
println request