PowerShell常用Regex和文法參考_PowerShell

來源:互聯網
上載者:User

本文介紹PowerShell中的Regex,各種不同的字元代表不同的含義,包括預留位置PlaceHolder、量詞Quantifier和邊界字元。

下面列舉PowerShell的Regex中可能出現的字元,以及它們表示的含義。

字串的匹配符(預留位置PlaceHolder)

. 這是一個點兒,表示分行符號之外的任意一個字元(Any character except newline (Equivalent: [^\n]))
[^abc] 指定的字元(abc)之外的任意一個字元,可以把abc換成其它字元組。(All characters except the ones specified)
[^a-z] 任意一個非小寫字母的字元(All characters except those in the region specified)
[abc] 指定的字元集中的任意一個,即abc中的任意一個(One of the characters)
[a-z] 指定的字元範圍中的任意一個,即任意一個小寫字母。One of the characters in the region
\a 響呤(Bell (ASCII 7))
\c Any character allowed in XML names
\cA-\cZ Control+A to Control+Z, ASCII 1 to ASCII 26
\d 任意一個數字,等同於[0-9](Any number (Equivalent: [0-9]))
\D 任意一個非數字。Any non-number
\e ESC鍵(Escape (ASCII 27))
\f Form Feed, (ASCII 12)
\n 換行Line break
\r 斷行符號Carriage return
\s 任意一個空白鍵(空白鍵如tab,換行)Any whitespace (space, tab, new line)
\S 任意一個非空白字元(Any non-whitespace)
\t tab鍵
\w 字母,數字和底線(Letter, number or underline)
\W \w的補集(Non-letter, number, or underline)

匹配次數(量詞Quantifier)

* 出現零次、1次、多次(Any (no occurrence, once, many times))
? 出現零次、1次(No occurrence or one occurrence)
{n,} 出現至少n次(At least n occurrences)
{n,m} 出現至少n次,最多m次(At least n occurrences, maximum m occurrences)
{n} 出現n次(Exactly n occurrences)
+ 出現1次、多次(One or many occurrences)

所有的匹配次數的符號,預設情況下都是貪婪的,即它將最大長度的進行匹配。如果想要得到最短的匹配,那就要在上面這組符號之後加一個問號(?)。

匹配邊界

$ 字串結束(End of text)
^ 字串開始(Start of text)
\b Word boundary
\B No word boundary
\G After last match (no overlaps)

關於PowerShellRegex參考,本文就介紹這麼多,希望對您有所協助,謝謝!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.