PC Review


Reply
Thread Tools Rate Thread

help on regex

 
 
=?Utf-8?B?QVZM?=
Guest
Posts: n/a
 
      5th Jun 2007
i want a reg exp for the below format..
1.0.00.0000

i tried as follows
\d\.\d\.\d{2}\.\d{4}

but it's accepting -ves numbers also(-1.0.00.0000)
I want only +ve numbers in my input..how do i check it?
 
Reply With Quote
 
 
 
 
Bryan Phillips
Guest
Posts: n/a
 
      6th Jun 2007
Try this:

[^-]\d\.\d\.\d{2}\.\d{4}

--
Bryan Phillips
MCT, MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com
Web Site: http://www.composablesystems.net



"AVL" <(E-Mail Removed)> wrote in message
news:2102DDD1-1141-4B13-BEDA-(E-Mail Removed):

> i want a reg exp for the below format..
> 1.0.00.0000
>
> i tried as follows
> \d\.\d\.\d{2}\.\d{4}
>
> but it's accepting -ves numbers also(-1.0.00.0000)
> I want only +ve numbers in my input..how do i check it?


 
Reply With Quote
 
 
 
 
=?Utf-8?B?T21lZ2FNYW4=?=
Guest
Posts: n/a
 
      7th Jun 2007
Try this

^(?!\-)\+?\d\.\d\.\d{2}\.\d{4}

I have added the beginning of line ^ and the match invalidator (?! ) which
if the item in the validator matches, the match becomes invalid. Hence if
there is a minus sign, the match is invalid. (Also added \+? which allows for
an optional + sign.

----
Check out MSDN's .Net Regex Forum
http://forums.microsoft.com/MSDN/Use....aspx?SiteID=1
 
Reply With Quote
 
=?Utf-8?B?T21lZ2FNYW4=?=
Guest
Posts: n/a
 
      7th Jun 2007
Try this

^(?!\-)\+?\d\.\d\.\d{2}\.\d{4}

or if you dont want to enforce the digits, repeat the patter of \d\. such as

^(?!\-)\+?(\d+\.?)+

These concepts are added

^ Beginning of Line to anchor it.
(?! ) Match Invalidator. If the item within matches, it invalidates the
whole match.
in your case if a - is at the beginning then it will invalidate.
\+? says look for literal +, zero or 1 item. Just to be consistent.






 
Reply With Quote
 
Alun Harford
Guest
Posts: n/a
 
      10th Jun 2007
AVL wrote:
> i want a reg exp for the below format..
> 1.0.00.0000
>
> i tried as follows
> \d\.\d\.\d{2}\.\d{4}
>
> but it's accepting -ves numbers also(-1.0.00.0000)
> I want only +ve numbers in my input..how do i check it?


Well that will accept:

foobar fibbles foobar1.0.00.0000foobar fibbles foobar

You're not enforcing matching the beginning and end of the input. Try:

^\d\.\d\.\d{2}\.\d{4}$

Alun Harford
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex: different options on different sections of the Regex? Ethan Strauss Microsoft C# .NET 4 11th Jul 2008 03:54 PM
Is there a good way to turn regex patterns into properly-escaped c# regex patterns? sherifffruitfly Microsoft C# .NET 3 11th Feb 2007 10:56 AM
Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine? =?Utf-8?B?SmViQnVzaGVsbA==?= Microsoft ASP .NET 2 22nd Oct 2005 03:43 PM
HELP NEEDED FAST!!! HELP HELP HELP HELP HELP HELP FAST HELP NEEDED Jonathan Windows XP General 10 13th Jan 2005 03:22 AM
Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! Help! -$- Windows XP Internet Explorer 2 21st Dec 2003 11:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:32 PM.