473,499 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regex : IsMatch static vs non-static issue

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
1 1382
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2961
by: Johnny | last post by:
I need to determine whether a text box contains a value that does not convert to a decimal. If the value does not convert to a decimal, I want to throw a MessageBox to have the user correct the...
1
1692
by: Colin Reid | last post by:
Hey MS, here's an apparent problem in the base class library. I pulled the email validation pattern "^((*)*@(()+(*)*\.)+{2,9})" from http://regexlib.com. If I validate the email address...
8
5514
by: Bibe | last post by:
I've been trying to get this going for awhile now, and need help. I've done a regex object, and when I use IsMatch, it's behavior is quite weird. I am trying to use Regex to make sure that a...
2
28665
by: Byron | last post by:
All I am trying to do is use Regex.IsMatch to validate that a string is either empty, or exactly 4 characters (digits) in length. In other words, the strings, "", and "1234" should pass, whereas...
3
241
by: Naveed Anwar Kharadi | last post by:
Hi people !!! I want to write a regular expression that fails when it finds two consecutive slashes (//) in the provided data. E.g. Data = "asdf//fghkj" Regex.IsMatch(Data) returns false.
4
2841
by: Jon Maz | last post by:
Hi All, Am getting frustrated trying to port the following (pretty simple) function to CSharp. The problem is that I'm lousy at Regular Expressions.... //from...
1
1435
by: larry | last post by:
I'm having trouble with a pattern match expression using regex. I need to have the first 4 characters as letters and the next 2 characters as digits. ex... PROJ12 - when trying "\D{4}\d{2}"...
5
2252
by: Dennis | last post by:
Should not the following return False if s="255xxxxyyy"? It seems to return True. Regex.IsMatch(s, "") -- Dennis in Houston
4
2781
by: ad | last post by:
I am useing VS2005 to develop wep application. I use a RegularExpress both in RegularExpressionValidator and Regex class to validate a value. The RegularExpress is 20|\-9|\-1|?\d{1} When I...
0
1518
by: Tidane | last post by:
Visual Basic.NET Framework 2.0 I've created a program to parse out text as the program recieved it and use Regex matching to decide what should be done. My problem is that the text is matching when...
0
7128
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7385
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5467
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4597
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
294
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.