Skip to content

Instantly share code, notes, and snippets.

@pkutaj
Last active January 15, 2022 01:51
Embed
What would you like to do?
Multiple Replaces and Ternary Operator
# Sometimes URL is copied from a browser and arrives as
# https://consul.foo.com/client/ami_size/edit
# Othertimes URL is copied from Consul CLI and arrives as
# client/ami_size
# And I just need the actual key, being 'ami_size' for the script
$url = ($url -match "^https://") ?
($url -replace "https://consul.foo.com/client/", "") -replace "/edit", "":
($url -replace "client/", "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment