473,804 Members | 4,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with a regular expression

Hi,
I would like to build a regular expression that allows
only a number with 3 integer the decimals separator and
other three decimals.
I've build the firt part in this way:
^([1-9]{1}|[1-9]{1}[0-9]{1}|100)$

Now I'am tring to build the second one but... it's quite
difficult.
Somebody could help me? This is what I've done:
^([1-9]{1}|[1-9]{1}[0-9]{1}|100)\.([0-9]{1}|[0-9]{2}|[0-9]
{3})$

But it doesn't work as I would... :-\
Thanks in advance!
Nov 15 '05 #1
3 2051
Chris probably hasn't seen this post yet :-)

try this while you wait
www.regexlib.com

"giulio santorini" <gi************ **@yahoo.it> wrote in message
news:09******** *************** *****@phx.gbl.. .
Hi,
I would like to build a regular expression that allows
only a number with 3 integer the decimals separator and
other three decimals.
I've build the firt part in this way:
^([1-9]{1}|[1-9]{1}[0-9]{1}|100)$

Now I'am tring to build the second one but... it's quite
difficult.
Somebody could help me? This is what I've done:
^([1-9]{1}|[1-9]{1}[0-9]{1}|100)\.([0-9]{1}|[0-9]{2}|[0-9]
{3})$

But it doesn't work as I would... :-\
Thanks in advance!

Nov 15 '05 #2
In article <09************ *************** *@phx.gbl>,
"giulio santorini" <gi************ **@yahoo.it> wrote:
Now I'am tring to build the second one but... it's quite
difficult.
Somebody could help me? This is what I've done:
^([1-9]{1}|[1-9]{1}[0-9]{1}|100)\.([0-9]{1}|[0-9]{2}|[0-9]
{3})$

But it doesn't work as I would... :-\

Tell us what you expect to happen, what actually happens, and why you
don't think that's right.

Give some examples of strings on which it should work but doesn't.
Give some examples of strings on which it shouldn't work but does.


All that aside, are you escaping the escape character--so that C#
doesn't digest your \ ? That is, you have the following, right?

^([1-9]{1}|[1-9]{1}[0-9]{1}|100)\\.( etc. )$

That is, \\. instead of \.
By the way, the {1} quantifiers are redundant. You could probably get
away with the following:

Regex r = new Regex("^([1-9][0-9]?|100)\\.([0-9]{1,3})$");
That regex looks for:
* the start of the string

then either

* one digit between 1 and 9
* and, optionally, one digit between 0 and 9

or

* the string 100

* a decimal point

* between one and three digits, each between 0 and 9

* the end of the string
Nov 15 '05 #3
see also Eric Gunnerson's Regular Expression workbench. This is quite
useful for figuring out what your expression is doing and getting it
to work.

http://www.gotdotnet.com/Community/U...1-4ee2729d7322

As guiulio mentioned, make sure you either escape your backslashes
(\\) or to make life simpler, always use @ in front of the whole
string.

string pattern = @"^mypatter\.wi th[1-9]funky\.characte rs$";

-mike mayer

"giulio santorini" <gi************ **@yahoo.it> wrote in message
news:09******** *************** *****@phx.gbl.. .
Hi,
I would like to build a regular expression that allows
only a number with 3 integer the decimals separator and
other three decimals.
I've build the firt part in this way:
^([1-9]{1}|[1-9]{1}[0-9]{1}|100)$

Now I'am tring to build the second one but... it's quite
difficult.
Somebody could help me? This is what I've done:
^([1-9]{1}|[1-9]{1}[0-9]{1}|100)\.([0-9]{1}|[0-9]{2}|[0-9]
{3})$

But it doesn't work as I would... :-\
Thanks in advance!

Nov 15 '05 #4

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

Similar topics

4
1611
by: andrewflanders | last post by:
I have an associative array of keys and values. I want to search a string for the existance of keys and replace them with the values in the array. The problem is that some of the keys resemble regular expressions but they are not so if I build the regular expression with a constructor it causes errors saying that the regular expression syntax is bad. I got around this problem by skipping the regular expression method and passing in the key...
4
5175
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following testMyColumn{1, 100}Test Basically I want the regular expression to add the word test infront of the
11
5396
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However, I want to use the text included within the brackets to do a lookup so that I can replace the expression with the new text. For example:
3
1720
by: Senna | last post by:
Hi all, Thru a HttpWebRequest and HttpWebResponse I get html like this(<pre> excluded). <pre> <tr> <td valign="top" align="right" class="SgSVT1BG" nowrap style=" padding-right: 6px "><div class="SgZText"><span
4
1366
by: | last post by:
Here is an interesting one. Running asp.net 2.0 beta 2. I have a regular expression used in a regex validator that works on the client side in Firefox but not in IE. Any ideas? IE always reports the field is invalid. The expression is: ^(?!\d)(?=.*\d)(?=.*)(?=.*)(?=.*).{8,25}$ If I enter "Test_Field1" Firefox considers it valid on client side, IE doesnt. Server side considers it valid too because when I submit the form in
0
9579
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
10330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10319
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
10076
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...
0
6851
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
5520
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...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4297
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 we have to send another system
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.