On The Value Of Tactics With Powershell's Multiple Find And Replace Oneliner

Pavol Kutaj
2 min readJan 15, 2022

--

The aim of this page📝 is to show a small tactical idiom from PowerShell to save space — which some may say is useless, some may say is elegant. I learned about the importance of tactics from chess, namely from Why Tactics? > Chesstactics.org:

Strategy and tactics both are important, but tactics are more important. If you’re a whiz at finding clever moves that take your opponent’s pieces, you will be a terrifying opponent, have a good time playing chess, and win lots of games regardless of whether you know a great deal about strategy. If you’re a whiz at strategy but not much good at tactics, you will have trouble winning or having fun because your pieces will keep getting taken.

This is controversial, and I am not saying it applies generally. For the countering voice from the world of engineering, see The Gospel of Evan: a not true dao of development:

Algorithms > Micro-optimizations, but this is easy to forget because…It’s hard to visualize the whole scope of the algorithm or system. Use (& build your own!) tools that increase observability.

1. multi-replacer

  • I have a URL and for a case, it arrives copied from a browser, I need to remove both parts of the beginning and end
  • I have two cases so I employ a ternary operator for the little case analysis
  • I also natural line continuators for better readability
  • use parenthesis to make multiple operations with -replace
  • it would work also without "" within the command, but I prefer Python's
Explicit is better than implicit

2. links

--

--

Pavol Kutaj

Today I Learnt | Infrastructure Support Engineer at snowplow.io with a passion for cloud infrastructure/terraform/python/docs. More at https://pavol.kutaj.com