PowerShell常用正則表達(dá)式和語法參考

2018-08-22 17:59 更新
這篇文章主要介紹了PowerShell常用正則表達(dá)式和語法參考,主要介紹PowerShell中的正則表達(dá)式和其含義,需要的朋友可以參考下本文介紹PowerShell中的正則表達(dá)式,各種不同的字符代表不同的含義,包括占位符PlaceHolder、量詞Quantifier和邊界字符。

下面列舉PowerShell的正則表達(dá)式中可能出現(xiàn)的字符,以及它們表示的含義。


一、字符串的匹配符(占位符PlaceHolder)

. 這是一個(gè)點(diǎn)兒,表示換行符之外的任意一個(gè)字符(Any character except newline (Equivalent: [^\n]))
[^abc] 指定的字符(abc)之外的任意一個(gè)字符,可以把a(bǔ)bc換成其它字符組。(All characters except the ones specified)
[^a-z] 任意一個(gè)非小寫字母的字符(All characters except those in the region specified)
[abc] 指定的字符集中的任意一個(gè),即abc中的任意一個(gè)(One of the characters)
[a-z] 指定的字符范圍中的任意一個(gè),即任意一個(gè)小寫字母。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 任意一個(gè)數(shù)字,等同于[0-9](Any number (Equivalent: [0-9]))
\D 任意一個(gè)非數(shù)字。Any non-number
\e ESC鍵(Escape (ASCII 27))
\f Form Feed, (ASCII 12)
\n 換行Line break
\r 回車Carriage return
\s 任意一個(gè)空白鍵(空白鍵如tab,換行)Any whitespace (space, tab, new line)
\S 任意一個(gè)非空白字符(Any non-whitespace)
\t tab鍵
\w 字母,數(shù)字和下劃線(Letter, number or underline)
\W \w的補(bǔ)集(Non-letter, number, or underline)

二、匹配次數(shù)(量詞Quantifier)

* 出現(xiàn)零次、1次、多次(Any (no occurrence, once, many times))
? 出現(xiàn)零次、1次(No occurrence or one occurrence)
{n,} 出現(xiàn)至少n次(At least n occurrences)
{n,m} 出現(xiàn)至少n次,最多m次(At least n occurrences, maximum m occurrences)
{n} 出現(xiàn)n次(Exactly n occurrences)
+ 出現(xiàn)1次、多次(One or many occurrences)
所有的匹配次數(shù)的符號(hào),默認(rèn)情況下都是貪婪的,即它將最大長度的進(jìn)行匹配。如果想要得到最短的匹配,那就要在上面這組符號(hào)之后加一個(gè)問號(hào)(?)。

四、匹配邊界

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

關(guān)于PowerShell正則表達(dá)式參考,本文就介紹這么多,希望對(duì)您有所幫助,謝謝!

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)