Last active
January 13, 2022 13:00
-
-
Save ThomsonTang/01d6ed07ed5a746e823c5e9187d12ebc to your computer and use it in GitHub Desktop.
change the value of a specified query string in a url.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* change the value of a specified query string in a url. | |
*/ | |
def updateUrlParameterValWithRegex(url, paraName, paraVal) { | |
assert url | |
def (path, paras) = url.tokenize('?') | |
println "the original url parameters:\n ${paras}" | |
def updatedUrl = paras.replaceFirst(/${paraName}=\w*/, "${paraName}=${paraVal}") | |
println "the updated url parameters:\n ${updatedUrl}" | |
"${path}${updatedUrl}" | |
} | |
def url = "http://lbgp.58corp.com/git/updateReleaseStatus?moudleId=14828087759030003&username=yufei03&jiraId=LBG-84" | |
updateUrlParameterValWithRegex(url, 'username', 'timmy') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment