-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
** EmailAddress ** MultiLineComment (Generator) * Use-Regex will now add the generator name as a capture name * Use-Regex will not handle errors running the RegEx, and attach the input object * Adding a reference document for saved regular expressions * Adding an example to Get-RegEx to generate that document * Fixing the example of an email address regex in Write-Regex
- Loading branch information
1 parent
ec3491d
commit f7a9bb1
Showing
17 changed files
with
191 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
: | ||
# Matches a colon | ||
: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# An email address (captures the UserName and Domain) | ||
(?<UserName>\w{1,1}[\w\.\-]{0,})(?:\@)(?<Domain>\w[\w\-]{0,}\.\w{1,}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
^|$ | ||
# This will match either a line start or end. | ||
^|$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<# | ||
.Synopsis | ||
Matches Multiline Comments | ||
.Description | ||
Matches Multline Comments from a variety of languages. | ||
Currently supported: PowerShell, C#, C++, JavaScript, Ruby, HTML, and XML | ||
When this generator is used with a piped in file, the extension will autodetect the format. | ||
If the format could not be autodetected, the match will always fail. | ||
#> | ||
param( | ||
[ValidateSet('PowerShell', 'C#', 'C++', 'C', 'JavaScript', 'Ruby', 'HTML', 'XML','')] | ||
[string] | ||
$Language = 'C' | ||
) | ||
|
||
if ($inputObject -and $inputObject -is [IO.FileInfo]) { | ||
$Language = | ||
if ('.h', '.cpp', '.c', '.cs', '.js' -contains $inputObject.Extension) { | ||
'C' | ||
} elseif ('.ps1', '.psm1', '.psd1' -contains $inputObject.Extension) { | ||
'PowerShell' | ||
} elseif ('.htm', '.html', '.xml', '.pswt' -contains $inputObject.Extension -or | ||
$inputObject.Extension -like '.*xml') { | ||
'XML' | ||
} | ||
} | ||
|
||
if (-not $PSBoundParameters.Language -and -not $Language) { | ||
return | ||
} | ||
|
||
|
||
switch ($Language) { | ||
PowerShell { | ||
@' | ||
\<\# # The opening tag | ||
(?<Block> | ||
(.|\s)+?(?=\#>) # anything until the closing tag | ||
) | ||
\#\> # the closing tag | ||
'@ | ||
} | ||
{$_ -match '(C\#)|(C\+\+)|(C)|(JavaScript)'} { | ||
@' | ||
/\* # The open comment | ||
(?<Block> | ||
(.|\s)+?(?=\*/) | ||
)\*/ | ||
'@ | ||
} | ||
Ruby { | ||
@' | ||
^=begin # begin line | ||
(?<Block>(.|\s)+?(?=\=end)) # anything that's not =end | ||
=end # end line | ||
'@ | ||
} | ||
{ $_ -match 'HTML|XML' } { | ||
@' | ||
<\!-- | ||
(?<Block>(.|\s)+?(?=-->)) | ||
--> | ||
'@ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# A newline | ||
# A newline (in either Windows (\r\n) or Unix (\n) form) | ||
(?>\r\n|\n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# Finds all text until the next word boundary | ||
# Finds all repeated text that is not whitespace or punctuation. | ||
[\S-[\p{P}]]+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
(?<Number>?<Decimals>) | ||
# Matches a decimal number with an exponent. | ||
(?<Number>?<Decimals>) | ||
(?:\^) | ||
(?<Exponent>?<Decimals>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
\s{0,} | ||
# This matches zero or more whitespace characters | ||
\s{0,} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
\p{P}+ | ||
# Matches any single or repeated punctuation. | ||
\p{P}+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
true|false | ||
# Matches the literal 'true' or 'false' | ||
true|false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|Name|Description|IsGenerator| | ||
|:---|:----------|:----------| | ||
|ArithmeticOperator|Simple Arithmetic Operators|False| | ||
|BalancedBrackets|Matches content in brackets, as long as it is balanced|False| | ||
|BalancedCode|Matches code balanced by a [, {, or ( | ||
|True| | ||
|BalancedCurlyBracket|Matches content in {}, as long as it is balanced|False| | ||
|BalancedParenthesis|Matches content in parenthesis, as long as it is balanced|False| | ||
|Colon|Matches a colon|False| | ||
|ColonOrEqual|Matches either a colon or an equal sign.|False| | ||
|Decimals|Matching any series of decimals is deceptively complicated|False| | ||
|Digits|Repeated Digits|False| | ||
|EmailAddress|An email address (captures the UserName and Domain)|False| | ||
|GenericBalancingExpression|This expression matches content that is within "balanced" punctuation. | ||
It does not validate that each type of open/close punctuation is valid. | ||
Just that it any open punctuation is matched by closed punctuation.|False| | ||
|GetMarkupTag|Gets one or more specific markup tags. By default, anchor tags. | ||
|True| | ||
|JSONProperty|A property within a JSON string|False| | ||
|LineEndsWithColon|This returns lines that end with a colon|False| | ||
|LineStartOrEnd|This will match either a line start or end.|False| | ||
|MultilineComment|Matches Multline Comments from a variety of languages. | ||
Currently supported: PowerShell, C#, C++, JavaScript, Ruby, HTML, and XML | ||
When this generator is used with a piped in file, the extension will autodetect the format. | ||
If the format could not be autodetected, the match will always fail. | ||
|True| | ||
|NewLine|A newline (in either Windows (\r\n) or Unix (\n) form)|False| | ||
|NextColon|This returns the position of the next colon, but not the next colon itself.|False| | ||
|NextWord|Finds all repeated text that is not whitespace or punctuation.|False| | ||
|NumberAndExponent|Matches a decimal number with an exponent.|False| | ||
|OptionalWhitespace|This matches zero or more whitespace characters|False| | ||
|PowerShellAttributeKeyValuePair|This expression extracts the key/value pairs from a PowerShell attribute body (the content within parenthesis)|False| | ||
|PowerShellDoubleQuoteString|A PowerShell double-quoted string|False| | ||
|PowerShellInlineHelpField|Matches specific fields from inline help | ||
|True| | ||
|PowerShellSingleQuoteString|Matches a single quoted string, escaped by double single-quotes|False| | ||
|Punctuation|Matches any single or repeated punctuation.|False| | ||
|StartsWithCapture|Matches if the string starts with a named capture, and captures the FirstCaptureName|False| | ||
|Tag|This will match a balanced markup tag.|False| | ||
|TrueOrFalse|Matches the literal 'true' or 'false'|False| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters