Regular Expressions 101

Community Patterns

123...6

C# Regex Class acts odd

1

Regular Expression
PCRE (PHP <7.3)

/
^([0-9]*)(\\*)$
/

Description

Based on my understanding of Regex, the string “10” matches the Regex “^([0-9])(\)$”. To validate it, I tried the regex and the text “10” on the website and it worked. But when I tried the same with C# code, it failed.Only by adding a "?", making the regex “^([0-9])(\)?$” makes the string "10" validate against the regex. I am confused why it behaves differently in the C# Regex class.

Submitted by anonymous - 10 years ago