PowerShell常用正則表達(dá)式和語法參考
本文介紹PowerShell中的正則表達(dá)式,各種不同的字符代表不同的含義,包括占位符PlaceHolder、量詞Quantifier和邊界字符。
下面列舉PowerShell的正則表達(dá)式中可能出現(xiàn)的字符,以及它們表示的含義。
字符串的匹配符(占位符PlaceHolder)
. 這是一個點(diǎn)兒,表示換行符之外的任意一個字符(Any character except newline (Equivalent: [^\n]))
[^abc] 指定的字符(abc)之外的任意一個字符,可以把a(bǔ)bc換成其它字符組。(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 任意一個數(shù)字,等同于[0-9](Any number (Equivalent: [0-9]))
\D 任意一個非數(shù)字。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 字母,數(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ù)的符號,默認(rèn)情況下都是貪婪的,即它將最大長度的進(jìn)行匹配。如果想要得到最短的匹配,那就要在上面這組符號之后加一個問號(?)。
匹配邊界
$ 字符串結(jié)束(End of text)
^ 字符串開始(Start of text)
\b Word boundary
\B No word boundary
\G After last match (no overlaps)
關(guān)于PowerShell正則表達(dá)式參考,本文就介紹這么多,希望對您有所幫助,謝謝!
相關(guān)文章
Powershell生成Windows密碼算法簡單學(xué)習(xí)
利用Powershell生成Windows密碼:密碼一共8位/字符的次序是隨機(jī)組成的等等,接下來為你詳細(xì)介紹下,感興趣的你可以參考下哈,希望對你學(xué)習(xí)Powershell有所幫助2013-03-03PowerShell查看本機(jī)文件關(guān)聯(lián)程序和默認(rèn)打開程序的方法
這篇文章主要介紹了PowerShell查看本機(jī)文件關(guān)聯(lián)程序和默認(rèn)打開程序的方法,本文給出了查看方法,同時給出了一份讀取結(jié)果,需要的朋友可以參考下2015-06-06PowerShell函數(shù)參數(shù)設(shè)置成自動識別數(shù)據(jù)類型的例子
這篇文章主要介紹了PowerShell函數(shù)參數(shù)設(shè)置成自動識別數(shù)據(jù)類型的例子,這個方法可以很方便的使用參數(shù)集,而不用每次指定名稱,需要的朋友可以參考下2014-07-07Powershell 腳本數(shù)字簽名實(shí)現(xiàn)方法
這篇文章主要介紹了Powershell 腳本數(shù)字簽名實(shí)現(xiàn)方法,需要的朋友可以參考下2017-10-10探索PowerShell (三) PowerShell下使用Aliases
這一節(jié)就來介紹PowerShell下的Aliases。在PowerShell中,為了習(xí)慣于使用,可以使用別名代替命令2012-12-12PowerShell小技巧之使用New-Module命令動態(tài)創(chuàng)建對象
這篇文章主要介紹了在PowerShell中使用New-Module命令動態(tài)創(chuàng)建對象,比New-Object高大上很多了吧2014-09-09Powershell檢查網(wǎng)站響應(yīng)并計(jì)算執(zhí)行時間例子
這篇文章主要介紹了Powershell檢查網(wǎng)站響應(yīng)并計(jì)算執(zhí)行時間例子,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-03-03