PowerShell Tutorial
Selected Reading
- PowerShell - Discussion
- PowerShell - Useful Resources
- PowerShell - Quick Guide
- PowerShell - Alias
- PowerShell - Brackets
- PowerShell - Backtick
- PowerShell - Regex
- PowerShell - Hashtables
- PowerShell - Array
- PowerShell - Conditions
- PowerShell - Looping
- PowerShell - Operators
- PowerShell - Special Variables
- PowerShell - Scripting
- PowerShell - Advanced Cmdlets
- PowerShell - Files I/O
- PowerShell - Dates and Timers
- PowerShell - Files and Folders
- PowerShell - Cmdlets
- PowerShell - Environment Setup
- PowerShell - Overview
- PowerShell - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
PowerShell - Regex
Powershell - Regular Expression
A regular expression is a special sequence of characters that helps you match or find other strings or sets of strings, using a speciapzed syntax held in a pattern. They can be used to search, edit, or manipulate text and data.
Here is the table psting down all the regular expression metacharacter syntax available in PowerShell −
Subexpression | Matches |
---|---|
^ | Matches the beginning of the pne. |
$ | Matches the end of the pne. |
. | Matches any single character except newpne. Using m option allows it to match the newpne as well. |
[...] | Matches any single character in brackets. |
[^...] | Matches any single character not in brackets. |
A | Beginning of the entire string. |
z | End of the entire string. |
End of the entire string except allowable final pne terminator. | |
re* | Matches 0 or more occurrences of the preceding expression. |
re+ | Matches 1 or more of the previous thing. |
re? | Matches 0 or 1 occurrence of the preceding expression. |
re{ n} | Matches exactly n number of occurrences of the preceding expression. |
re{ n,} | Matches n or more occurrences of the preceding expression. |
re{ n, m} | Matches at least n and at most m occurrences of the preceding expression. |
a| b | Matches either a or b. |
(re) | Groups regular expressions and remembers the matched text. |
(?: re) | Groups regular expressions without remembering the matched text. |
(?> re) | Matches the independent pattern without backtracking. |
w | Matches the word characters. |
W | Matches the nonword characters. |
s | Matches the whitespace. Equivalent to [ f]. |
S | Matches the nonwhitespace. |
d | Matches the digits. Equivalent to [0-9]. |
D | Matches the nondigits. |
A | Matches the beginning of the string. |
Matches the end of the string. If a newpne exists, it matches just before newpne. | |
z | Matches the end of the string. |
G | Matches the point where the last match finished. |
Back-reference to capture group number "n". | |
Matches the word boundaries when outside the brackets. Matches the backspace (0x08) when inside the brackets. | |
B | Matches the nonword boundaries. |
, , etc. | Matches newpnes, carriage returns, tabs, etc. |
Q | Escape (quote) all characters up to E. |
E | Ends quoting begun with Q. |
Here is a complete examples showing how to use regex in PowerShell;
Sr.No. | Match & Description |
---|---|
1 | Example of supported regular expression characters. |
2 | Example of supported character classes. |
3 | Example of supported quantifiers. |