Last active
May 24, 2020 07:32
-
-
Save khalidelboray/c120a29f6dac83bc68dcd514da2640c9 to your computer and use it in GitHub Desktop.
Chenge Values of all params with one value
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
# Powershell escaped | |
write "https://google.com/?`nhttps://google.com/?a=1`nhttps://google.com/?param=value#frag" | raku -e "$*IN.lines.map(-> `$url { `$url ~~ /['?'[(<-[`=`&]>+)*%'=']*%'&']/;put ($/[0] ?? `$url.substr(0,$/.from + 1) ~ $/[0].rotor(2).map({.[0] ~ '=' ~ @*ARGS[0] }).join('&') !! `$url);})" REPLACE | |
# OR | |
# removed $url and used the topic variable for shorter version | |
write "https://google.com/?`nhttps://google.com/?a=1`nhttps://google.com/?param=value#frag" | raku -e "$*IN.lines.map({ / ['?' [ (<-[`=`&]>+) * % '=' ] * % '&' ] /;put ($/[0] ?? .substr(0,$/.from + 1) ~ $/[0].rotor(2).map({.[0] ~ '=' ~ @*ARGS[0] }).join('&') !! `$_);})" REPLACE | |
# OUTPUT : | |
https://google.com/? | |
https://google.com/?a=REPLACE | |
https://google.com/?param=REPLACE | |
# Raku code | |
for $*IN.lines -> $url { | |
$url ~~ / ['?' [ (<-[=&]>+) * % '=' ] * % '&' ] /; | |
# if the url has a query string | |
if $/[0] { | |
# $url.substr(0,$/.from + 1) the url without anything after the `?` | |
# $/[0].rotor(2) get a list of lists contains the name and value of each param | |
# .[0] ~ '=' ~ @*ARGS[0] param_name=THEREPLACEMENT | |
put $url.substr(0,$/.from + 1) ~ $/[0].rotor(2).map({.[0] ~ '=' ~ @*ARGS[0] }).join('&'); | |
} else { | |
put $url; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment