Forum Discussion

SagarSingh's avatar
SagarSingh
New Contributor
11 years ago

Regex in Groovy Scripting of SoapUI

Hi Team

Im an trying to write regular expression for a tag "<keyboard>Qwerty~12-qwerty</keyboard>", i need to write regex to find the entire tag not just the tag name or its contents, instead regex for complete "<keyboard>Qwerty~12-qwerty</keyboard>" and replace it. Tried various ways from Google but it shows either symbols like / and * are not allowed in Groovying scripting inside SoapUI

def request4 = request2.replace(<keyboard>*</keyboard>', "")
def request4 = request2.replace(\<conversationId\>\*\<\/conversationId\>', "")

Can you help me to find a way to resolve it.

2 Replies

  • nmrao's avatar
    nmrao
    Icon for Champion Level 1 rankChampion Level 1
    Here is the sample code(defined request here itself for testing, you may remove that):


    def request='''
    apple
    orange
    y
    banana
    <keyboard>Qwerty~12-qwerty</keyboard>
    <keyboard>Qwerty~24-qwerty</keyboard>
    apple
    orange
    y
    banana
    <conversationId>sfksjkdjf2213123</conversationId>
    <conversationId>ruieui234343213123</conversationId>
    '''
    def regEx1 = ~/(<keyboard>.+<\/keyboard>)/
    def newRequest = request.replaceAll(regEx1,'')
    log.info newRequest
  • SagarSingh's avatar
    SagarSingh
    New Contributor
    Hi Rao

    Fantastic..!! it works fine.. Thank you so much for such a quick response.
    SoapUI Rocks..!!