「PowerShell」match正規表現で文字列を比較するサンプル

書式
文字列 -like 表現式
文字列 -match 正規表現式
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#ワイルドカードlike
if ("arkgame" -like "a*") {
echo "study skill in arkgame.com"
}
#ワイルドカードnotlike
if ("testga" -notlike "?ab") {
echo "AAA"
}
#正規表現match
if ("test" -match "[a-z]+") {
echo "this is a test data"
}
if ("567" -match "[0-9]+") {
echo "digital number"
}
#ワイルドカードlike if ("arkgame" -like "a*") { echo "study skill in arkgame.com" } #ワイルドカードnotlike if ("testga" -notlike "?ab") { echo "AAA" } #正規表現match if ("test" -match "[a-z]+") { echo "this is a test data" } if ("567" -match "[0-9]+") { echo "digital number" }
#ワイルドカードlike
if ("arkgame" -like "a*") {
    echo "study skill in arkgame.com"
}
#ワイルドカードnotlike
if ("testga" -notlike "?ab") {
    echo "AAA"
}
#正規表現match
if ("test" -match "[a-z]+") {
    echo "this is a test data"
}
if ("567" -match "[0-9]+") {
    echo "digital number"
}

実行結果
> .\test.ps1
study skill in arkgame.com
AAA
this is a test data
digital number

PowerShell

Posted by arkgame