groovysoapui

Removing special characters from a string In a Groovy Script


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?


Solution

  • Use below code :

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

    instead of

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