How do I know which options are available in a RegexOptions enumeration?

How to use this function from a powershell script to perform a case-insensitive match using an operator -cmatch:

static System.Text.RegularExpressions.Match Match(
     string input, 
     string pattern,
     System.Text.RegularExpressions.RegexOptions options)

I think something like this:

PS>  $input = "one two three"

PS>  $m = [regex]::Match($input, "one", ????)

The part that I am asking is about the ????above.

How do you see what is System.Text.RegularExpressions.RegexOptionsavailable from the powershell prompt and what syntax is it to use in the code above?

+4
source share
2 answers

An easy cheat to see which options are available in an enumeration is to use the tab at the PowerShell or ISE prompt. Start with [System.Text.RegularExpressions.RegexOptions]::, and then use CTRL SPACE(or TAB) to view the options.

, RegexOptions , :

[System.Enum]::GetNames([System.Text.RegularExpressions.RegexOptions])

enum PowerShell, ( ):

[System.Text.RegularExpressions.RegexOptions]::IgnoreCase

(1), , 'IgnoreCase'.

: [regex]::Match() . [System.Text.RegularExpressions.RegexOptions]::None ( 0 'None').

, , IgnoreCase, .

-, . -bor ( ):

$myOptions = [System.Text.RegularExpressions.RegexOptions]::IgnoreCase -bor 
        [System.Text.RegularExpressions.RegexOptions]::SingleLine -bor
        [System.Text.RegularExpressions.RegexOptions]::IgnorePatternWhitespace

PowerShell . mklement0 , , PowerShell .

, 'IgnoreCase, SingleLine, IgnorePatternWhitespace' , RegexOptions. :

$myOptions = 'IgnoreCase, SingleLine, IgnorePatternWhitespace' -as [System.Text.RegularExpressions.RegexOptions]
$myOptions = [System.Text.RegularExpressions.RegexOptions]'IgnoreCase, SingleLine, IgnorePatternWhitespace'
+6

:

PS> using namespace System.Text.RegularExpressions

PS> [Enum]::GetNames([RegexOptions])
None
IgnoreCase
Multiline
ExplicitCapture
Compiled
Singleline
IgnorePatternWhitespace
RightToLeft
ECMAScript
CultureInvariant

PS>  $input = "one two three"

PS>  $m = [regex]::Match($input, "one", [RegexOptions]::IgnoreCase)
+1

Source: https://habr.com/ru/post/1692464/


All Articles