Skip to content

Instantly share code, notes, and snippets.

@gitfvb
Created June 20, 2018 07:27
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 gitfvb/7b96ac31fbedca36c2385a90b7db2f8e to your computer and use it in GitHub Desktop.
Save gitfvb/7b96ac31fbedca36c2385a90b7db2f8e to your computer and use it in GitHub Desktop.
regex with powershell examples
# the task is to match everything between SELECT and FROM
$string = "SELECT abc FROM def"
$pattern = '(?<=SELECT\s)(.*)(?=\sFROM)'
# search for pattern and output it
$string | Select-String $pattern -AllMatches | % {$_.Matches}| % {$_.Value}
# replace the match with something else
$string -replace $pattern, 'xyz'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment