Skip to content

Regex does not match, given a character-range from non-peripheral minus #108335

Open
@ItaiTzur76

Description

@ItaiTzur76

URL(s)

https://GitHub.com/microsoft/referencesource/blob/master/README.md

Description

I need to match +, -, ., / or a digit. Since all characters from - to 9 are in the ASCII range I need I used @"[+\--9]" (i.e. "match + or any single character from - to 9") as the Regex pattern.
However, the following expression:

System.Text.RegularExpressions.Regex.IsMatch(input: "3", pattern: @"[+\--9]")

returns false.
I made sure I followed Microsoft's Positive character group instructions.
To double-check, I tried it at various online Regex tester websites (Regex101, RegExr, RegexLearn) and they all matched 3 when I provided [+\--9] as pattern and 3 as input.

Expected behavior:

The expression

System.Text.RegularExpressions.Regex.IsMatch(input: "3", pattern: @"[+\--9]")

returns true.

Actual behavior:

The expression

System.Text.RegularExpressions.Regex.IsMatch(input: "3", pattern: @"[+\--9]")

returns false.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions