Created
June 20, 2018 07:27
-
-
Save gitfvb/7b96ac31fbedca36c2385a90b7db2f8e to your computer and use it in GitHub Desktop.
regex with powershell examples
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
# 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