This article introduces regular expressions in PowerShell, and various characters represent different meanings, including placeholder placeholder, quantifier quantifier, and boundary characters.
The following lists characters that may appear in the regular expression of PowerShell, and what they mean.
Match character for string (placeholder placeholder)
. This is a bit, representing any character other than a newline character (any character except newline (equivalent: [^\n])
[^ABC] Any character other than the character (ABC) that you specify, you can change ABC to another character group. (all characters except the ones specified)
[^a-z] Any character that is not a lowercase letter (all characters except those in the region)
Any of the character sets specified by [ABC], that is, any of the ABC (one of the characters)
[A-z] any of the range of characters specified, that is, any one lowercase letter. One of the characters in the region
\a (for Bell (ASCII 7))
\c any character allowed in XML names
\ca-\cz control+a to Control+z, ASCII 1 to ASCII 26
\d any number, equivalent to [0-9] (equivalent: [0-9])
\d any number of non-numeric. Any Non-number
\e ESC (Escape (ASCII 27))
\f Form Feed, (ASCII 12)
\ n linefeed line break
\ r Enter Carriage return
\s any blank key (blank key such as tab, newline) any whitespace (spaces, tab, new Line)
\s any one of the non-white-space characters (any non-whitespace)
\ t Tab key
\w letters, numbers and underscores (letter, number or underline)
\w \w's complement (non-letter, number, or underline)
Number of matches (quantifier quantifier)
* 0, 1 times, multiple (any (no occurrence, once, many times))
? 0 times, 1 times (No occurrence or one occurrence)
{N,} appears at least n times (at least n occurrences)
{n,m} appears at least n times, up to M times (at least n occurrences, maximum m occurrences)
{n} appears n times (exactly n occurrences)
+ appears 1 times, multiple times (one or many occurrences)
All the symbols for the number of matches are greedy by default, that is, it matches the maximum length. If you want to get the shortest match, add a question mark (?) after the symbol above.
Matching boundaries
$ string Ending (end of text)
^ String Start (start of text)
\b Word Boundary
\b No Word boundary
\g after the last match (no overlaps)
About PowerShell Regular expression reference, this article introduces so many, hope to help you, thank you!