about_Regular_Expressions

업데이트 날짜: 2014년 5월

적용 대상: Windows PowerShell 2.0, Windows PowerShell 3.0, Windows PowerShell 4.0, Windows PowerShell 5.0

여기에 소개를 삽입합니다.

항목

about_Regular_Expressions

간단한 설명

Windows PowerShell®에 정규식을 설명합니다.

자세한 설명

Windows PowerShell은(는) 다음과 같은 정규식 문자를 지원합니다.

        Format   Logic                            Example
        -------- -------------------------------  -----------------------
        value    Matches exact characters         "book" -match "oo"
                 anywhere in the original value.

        .        Matches any single character.    "copy" -match "c..y"

        [value]  Matches at least one of the      "big" -match "b[iou]g"
                 characters in the brackets.

        [range]  Matches at least one of the      "and" -match "[a-e]nd"
                 characters within the range.
                 The use of a hyphen (–) allows 
                 you to specify an adjacent 
                 character.

        [^]      Matches any characters except    "and" -match "[^brt]nd"
                 those in brackets.

        ^        Matches the beginning            "book" -match "^bo"
                 characters.

        $        Matches the end characters.      "book" -match "ok$"

        *        Matches any instances            "baggy" -match "g*"
                 of the preceding character.

        ?        Matches zero or one instance     "baggy" -match "g?"
                 of the preceding character.

        \        Matches the character that       "Try$" -match "Try\$"
                 follows as an escaped character.

Windows PowerShell은(는) Microsoft .NET Framework 정규식에서 사용할 수 있는 문자 클래스를 지원합니다.

        Format   Logic                            Example
        -------- -------------------------------  -----------------------
        \p{name} Matches any character in the     "abcd defg" -match "\p{Ll}+"
                 named character class specified 
                 by {name}. Supported names are 
                 Unicode groups and block 
                 ranges such as Ll, Nd, 
                 Z, IsGreek, and IsBoxDrawing.
 
        \P{name} Matches text not included in     1234 -match "\P{Ll}+"
                 the groups and block ranges 
                 specified in {name}.
 
        \w       Matches any word character.      "abcd defg" -match "\w+"
                 Equivalent to the Unicode        (this matches abcd)
                 character categories [\p{Ll}
                 \p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Pc}]. 
                 If ECMAScript-compliant behavior 
                 is specified with the ECMAScript 
                 option, \w is equivalent to 
                 [a-zA-Z_0-9].
 
        \W       Matches any nonword character.   "abcd defg" -match "\W+"
                 Equivalent to the Unicode        (This matches the space)
                 categories [^\p{Ll}\p{Lu}\p{Lt}
                 \p{Lo}\p{Nd}\p{Pc}].
 
        \s       Matches any white-space          "abcd defg" -match "\s+"
                 character.  Equivalent to the 
                 Unicode character categories 
                 [\f\n\r\t\v\x85\p{Z}].
 
        \S       Matches any non-white-space      "abcd defg" -match "\S+"
                 character. Equivalent to the 
                 Unicode character categories 
                 [^\f\n\r\t\v\x85\p{Z}].
 
        \d       Matches any decimal digit.       12345 -match "\d+"
                 Equivalent to \p{Nd} for 
                 Unicode and [0-9] for non-
                 Unicode behavior.
 
        \D       Matches any nondigit.            "abcd" -match "\D+"
                 Equivalent  to \P{Nd} for 
                 Unicode and [^0-9] for non-
                 Unicode behavior.

Windows PowerShell은(는) NET Framework 정규식에서 사용할 수 있는 수량자를 지원합니다. 다음은 수량자의 예입니다.

        Format   Logic                            Example
        -------- -------------------------------  -----------------------
        *        Specifies zero or more matches;  "abc" -match "\w*"
                 for example, \w* or (abc)*. 
                 Equivalent to {0,}.
  
        +        Matches repeating instances of   "xyxyxy" -match "xy+"
                 the preceding characters.

        ?        Specifies zero or one matches;   "abc" -match "\w?"
                 for example, \w? or (abc)?. 
                 Equivalent to {0,1}.
 
        {n}      Specifies exactly n matches;     "abc" -match "\w{2}"
                 for example, (pizza){2}. 
        
        {n,}     Specifies at least n matches;    "abc" -match "\w{2,}"
                 for example, (abc){2,}. 
        
        {n,m}    Specifies at least n, but no     "abc" -match "\w{2,3}"
                 more than m, matches.

이전 테이블에서 표시된 비교는 모두 True 값입니다.

정규식에 사용되는 이스케이프 문자인 백슬래시(\)는 Windows PowerShell에 사용되는 이스케이프 문자와 다릅니다. Windows PowerShell에 사용되는 이스케이프 문자는 백틱 문자(`)입니다.(ASCII 96)

자세한 정보는 http://go.microsoft.com/fwlink/?LinkId=133231에서 Microsoft Developer Network(MSDN)의 "정규식 언어 요소"를 참조하세요.

참고 항목

about_comparison_operators

about_Operators

커뮤니티 추가 항목

추가
표시: