Skip to content

Instantly share code, notes, and snippets.

@pkutaj
Last active January 15, 2022 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkutaj/37dcdd2c2b5c272fc6a957f3de976439 to your computer and use it in GitHub Desktop.
Save pkutaj/37dcdd2c2b5c272fc6a957f3de976439 to your computer and use it in GitHub Desktop.
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