473,796 Members | 2,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The Regex problem

ad
I am useing VS2005 to develop wep application.
I use a RegularExpress both in RegularExpressi onValidator and Regex class to
validate a value.
The RegularExpress is 20|\-9|\-1|[1]?\d{1}

When I enter 33 and validate with RegularExpressi onValidator, it fail to
pass.
But when I validate with regex class :
Regex.IsMatch(S ight0L, @"20|\-9|\-1|[1]?\d{1}");

it passed!!

Why, the results are different?



Jul 19 '06 #1
4 2799
* ad wrote, On 19-7-2006 23:52:
I am useing VS2005 to develop wep application.
I use a RegularExpress both in RegularExpressi onValidator and Regex class to
validate a value.
The RegularExpress is 20|\-9|\-1|[1]?\d{1}

When I enter 33 and validate with RegularExpressi onValidator, it fail to
pass.
But when I validate with regex class :
Regex.IsMatch(S ight0L, @"20|\-9|\-1|[1]?\d{1}");

it passed!!

Why, the results are different?



RegEx.IsMatch uses the .Net regular expression library while the
clientside validator will use the Javascript library. You should be able
to simulate the Javascriptlibar y by setting the RegexOptions.EC MAScript

Regex.IsMatch(S ight0L, @"20|\-9|\-1|[1]?\d{1}", RegexOptions.EC MAScript);

Note that your regex contains a few errors that might be causing this:
(20|-9|-1|1?\d) is probably closer to your needs.

Note that:
'-' is no special character except in character classes (between [ and
]) so no escaping is needed here

[1] is the same as 1, so you can lose the [ and ].

\d{1} is the same as \d, so you can lose the {1}.

It is best to add ( and ) when you're using the '|'.

With these changes both libraries should give the same result.

Jesse Houwing
Jul 19 '06 #2
ad
Thanks,
My intention of RegularExpress is to test a integer value, if the value :
if ((iSight<=20 && iSight>=0) | (iSight==-1 | iSight==-9)) then pass

When I test with value 44,
My 20|\-9|\-1|[1]?\d{1} will faill when use RegularExpressi onValidator but
passed with Regex class.
I have tried the regular expressin you mentioned about, but it is passed too
when when with Regex class.

"Jesse Houwing" <je***********@ nospam-sogeti.nl>
???????:e4***** *********@TK2MS FTNGP05.phx.gbl ...
>* ad wrote, On 19-7-2006 23:52:
>I am useing VS2005 to develop wep application.
I use a RegularExpress both in RegularExpressi onValidator and Regex class
to validate a value.
The RegularExpress is 20|\-9|\-1|[1]?\d{1} When I enter 33 and validate
with RegularExpressi onValidator, it fail to pass.
But when I validate with regex class :
Regex.IsMatch( Sight0L, @"20|\-9|\-1|[1]?\d{1}");

it passed!!

Why, the results are different?




RegEx.IsMatch uses the .Net regular expression library while the
clientside validator will use the Javascript library. You should be able
to simulate the Javascriptlibar y by setting the RegexOptions.EC MAScript

Regex.IsMatch(S ight0L, @"20|\-9|\-1|[1]?\d{1}", RegexOptions.EC MAScript);

Note that your regex contains a few errors that might be causing this:
(20|-9|-1|1?\d) is probably closer to your needs.

Note that:
'-' is no special character except in character classes (between [ and ])
so no escaping is needed here

[1] is the same as 1, so you can lose the [ and ].

\d{1} is the same as \d, so you can lose the {1}.

It is best to add ( and ) when you're using the '|'.

With these changes both libraries should give the same result.

Jesse Houwing

Jul 19 '06 #3
* ad wrote, On 20-7-2006 1:53:
Thanks,
My intention of RegularExpress is to test a integer value, if the value :
if ((iSight<=20 && iSight>=0) | (iSight==-1 | iSight==-9)) then pass

When I test with value 44,
My 20|\-9|\-1|[1]?\d{1} will faill when use RegularExpressi onValidator but
passed with Regex class.
I have tried the regular expressin you mentioned about, but it is passed too
when when with Regex class.
Ok, just add ^ and $ to contrain the regex to the whole input like this:

bool x = Regex..IsMatch( "44", @"^(20|-9|-1|1?\d)$");

It should do the trick.
>
"Jesse Houwing" <je***********@ nospam-sogeti.nl>
???????:e4***** *********@TK2MS FTNGP05.phx.gbl ...
>* ad wrote, On 19-7-2006 23:52:
>>I am useing VS2005 to develop wep application.
I use a RegularExpress both in RegularExpressi onValidator and Regex class
to validate a value.
The RegularExpress is 20|\-9|\-1|[1]?\d{1} When I enter 33 and validate
with RegularExpressi onValidator, it fail to pass.
But when I validate with regex class :
Regex.IsMatch (Sight0L, @"20|\-9|\-1|[1]?\d{1}");

it passed!!

Why, the results are different?



RegEx.IsMatc h uses the .Net regular expression library while the
clientside validator will use the Javascript library. You should be able
to simulate the Javascriptlibar y by setting the RegexOptions.EC MAScript

Regex.IsMatch( Sight0L, @"20|\-9|\-1|[1]?\d{1}", RegexOptions.EC MAScript);

Note that your regex contains a few errors that might be causing this:
(20|-9|-1|1?\d) is probably closer to your needs.

Note that:
'-' is no special character except in character classes (between [ and ])
so no escaping is needed here

[1] is the same as 1, so you can lose the [ and ].

\d{1} is the same as \d, so you can lose the {1}.

It is best to add ( and ) when you're using the '|'.

With these changes both libraries should give the same result.

Jesse Houwing

Jul 20 '06 #4
I am useing VS2005 to develop wep application.
I use a RegularExpress both in RegularExpressi onValidator and Regex class to
validate a value.
The RegularExpress is 20|\-9|\-1|[1]?\d{1}

When I enter 33 and validate with RegularExpressi onValidator, it fail to
pass.
But when I validate with regex class :
Regex.IsMatch(S ight0L, @"20|\-9|\-1|[1]?\d{1}");

it passed!!

Why, the results are different?
The RegularExpressi onValidator requires the entire string to be
matched. In effect it matches against "^<your RE>$".
When you use Regex.Match, it matches on a single "3", not on the entire
string. It matches the [1]?\d{1} part, because the {1}? is optional.

Hans Kesting
Jul 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2087
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 http://support.microsoft.com/default.aspx?scid=kb;EN-US;246800 function fxnParseIt() { var sInputString = 'asp and database';
4
9772
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a numeric value according to an arbitrary regular expression.
7
2619
by: bill tie | last post by:
I'd appreciate it if you could advise. 1. How do I replace "\" (backslash) with anything? 2. Suppose I want to replace (a) every occurrence of characters "a", "b", "c", "d" with "x", (b) every occurrence of characters "p", "q", "r", "s" with "y". Right now, I do it as follows:
6
4800
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search string. It's actually the input string into a Microsoft Index Server search. The string will consist of words, perhaps enclosed in quotes or parentheses. I'd like to use Regex to pull out the words, or the phrases if the words are enclosed in quotes....
17
3982
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher http://forta.com/books/0672325667/
3
2120
by: jg | last post by:
I made a mistake somewhere in my vb code and I look, check and read against the articles and help on regex, I still can't find the mistake I made. I know my test string and the test patterns works, because I used on a vs. script to check. I also believe I foolwed followed the regex syntax for dotnet. here is the source code for the function and testing Public Function regtest(ByVal StringIn As String, ByVal patrn As
6
4859
by: Talin | last post by:
I've run in to this problem a couple of times. Say I have a piece of text that I want to test against a large number of regular expressions, where a different action is taken based on which regex successfully matched. The naive approach is to loop through each regex, and stop when one succeeds. However, I am finding this to be too slow for my application -- currently 30% of the run time is being taken up in the regex matching. I thought...
16
2254
by: Mark Chambers | last post by:
Hi there, I'm seeking opinions on the use of regular expression searching. Is there general consensus on whether it's now a best practice to rely on this rather than rolling your own (string) pattern search functions. Where performance is an issue you can alway write your own specialized routine of course. However, for the occasional pattern search where performance isn't an issue, would most seasoned .NET developers rely on "Regex" and...
7
2232
by: =?Utf-8?B?amFj?= | last post by:
Hi, I have problems with following code and don’t find the bug : // Set ArrayList aArray = new ArrayList(); regStr = new Regex(@"\?)*(\d+)\]"); if(text != null && regStr.IsMatch(text)) {
1
12214
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose is that I seek out terms which are in a glossary on our site, and automatically link to this definition. Its slightly complex becase certain elements have to be ignored, for exampleI dont want to add links within existing links, or for example link...
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10467
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10201
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2931
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.