Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing special characters from a string In a Groovy Script

Tags:

groovy

soapui

I am looking to remove special characters from a string using groovy, i'm nearly there but it is removing the white spaces that are already in place which I want to keep. I only want to remove the special characters (and not leave a whitespace). I am running the below on a PostCode L&65$$ OBH

def removespecialpostcodce = PostCode.replaceAll("[^a-zA-Z0-9]+","")
log.info removespecialpostcodce 

Currently it returns L65OBH but I am looking for it to return L65 OBH

Can anyone help?

like image 574
csman Avatar asked Mar 13 '23 17:03

csman


1 Answers

Use below code :

 PostCode.replaceAll("[^a-zA-Z0-9 ]+","")

instead of

 PostCode.replaceAll("[^a-zA-Z0-9]+","")
like image 151
hedha Avatar answered Apr 07 '23 06:04

hedha