Search code examples
rubychef-infrachef-recipe

How to remove a part of string?


I am new to Ruby and currently I am trying to take out a part from the http request string.

Request : POST /test/userRegistration?id=1234&name=John&address=UK

Is there any way to take out "name=John&" using slice, gsub or any other method ? Output should be POST /test/userRegistration?id=1234&address=UK

Note : The value of "name" parameter can be different every time

Thanks


Solution

  • Try this ...

    str = "POST /test/userRegistration?id=1234&name=John&address=UK"
    str = str.sub(/&name=.+&/, '&')
    str
    => "POST /test/userRegistration?id=1234&address=UK"