Regex : IsMatch static vs non-static issue

B

Brian Christensen

Came across the following which puzzled me a bit. I havnt been able to
find anyting related to the issue so I hope that one in this group
might me be able to clarify things for me:

When executing the code

string dateTimeTest = "23-12-2006 22:10";

string regexStr = @"^(?=\d)(?:(?!(?:(?:0?[5-9]|1[0-4])(?:\.|-|\/)10(?:
\.|-|\/)(?:1582))|(?:(?:0?[3-9]|1[0-3])(?:\.|-|\/)0?9(?:\.|-|\/)(?:
1752)))(31(?!(?:\.|-|\/)(?:0?[2469]|11))|30(?!(?:\.|-|\/)0?2)|(?:29(?:
(?!(?:\.|-|\/)0?2(?:\.|-|\/))|(?=\D0?2\D(?:(?!000[04]|(?:(?:1[^0-6]|
[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])
(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|2[0-8]|
1\d|0?[1-9])([-.\/])(1[012]|(?:0?[1-9]))\2((?=(?:00(?:4[0-5]|[0-3]?\d)
\x20BC)|(?:\d{4}(?:$|(?=\x20\d)\x20)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)
\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:
[01]\d|2[0-3])(?::[0-5]\d){1,2})?$"

Regex regex = new Regex(
regexStr,
RegexOptions.IgnoreCase
| RegexOptions.Multiline
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);

bool test1 = regex.IsMatch(dateTimeTest);
bool test2 = System.Text.Regex.IsMatch(regexStr, dateTimeTest,
RegexOptions.IgnoreCase |
RegexOptions.Multiline |
RegexOptions.IgnorePatternWhitespace |
RegexOptions.Compiled))

test1 returns true but test2 returns false - I would of course expect
both to return true.

What am I missing?

Kind regards,
Brian
 
A

Alexey Smirnov

Brian Christensen said:
test1 returns true but test2 returns false - I would of course expect
both to return true.

What am I missing?

Regex.IsMatch(dateTimeTest, regexStr, ....

because the first parameter must be an input string

public static bool IsMatch (
string input,
string pattern,
RegexOptions options
)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Regex performance issue 6
Windows 7 Duplicate files. 1
Q: validation expression 5
Excel Converting rows into each individual reports 0
Help with countifs 1
REGEX for CUSIP followed by two numbers. 1
Replace email 1
Finding dynamic maxima 8

Top