PowerShell common Regular expressions and grammatical reference _powershell

Source: Internet
Author: User
Tags lowercase

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.