By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,317 Members | 2,419 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,317 IT Pros & Developers. It's quick & easy.

Regex : IsMatch static vs non-static issue

P: n/a
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}(?:\x20 BC)?)(?:$|(?=\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

May 17 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Brian Christensen" <bc****@usa.netwrote in message
news:11**********************@h2g2000hsg.googlegro ups.com...
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
)
May 17 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.