Re: RegExp Again!

Re: RegExp Again!

am 29.03.2008 20:28:46 von rn5a

On Mar 28, 7:46=A0pm, "Lloyd Sheen" wrote:
> "RN1" wrote in message
>
> news:e4dbd317-a37d-4632-8786-d05581b0199b@n58g2000hsf.google groups.com...
>
>
>
>
>
> > Using Regular Expression, I want to ensure that users enter either a 2-
> > digit or a 3-digit whole number in a TextBox. This is how I framed the
> > ValidationExpression in the RegularExpressionValidator:
>
> > ------------------------------------------------------------ ------------=
---=AD-----
> >
> > "
> > Display=3D"dynamic" ErrorMessage=3D"Invalid Text"
> > ValidationExpression=3D"[0-9]{3}|[0-9]{2}" runat=3D"server"/>
> > ------------------------------------------------------------ ------------=
---=AD-----
>
> > Suppose a user enters 16 & 216 in the TextBox. As expected, both the
> > numbers return True but if I just reverse the ValidationExpression
> > i.e. change the ValidationExpression from
>
> > [0-9]{3}|[0-9]{2}
>
> > to
>
> > [0-9]{2}|[0-9]{3}
>
> > & then input 16 & 216 in the TextBox, 16 correctly evaluates to True
> > but 216 strangely evaluates to False!
>
> > After a plethora of trial & error methods, I realized that if the
> > second ValidationExpression (the one which evaluates 216 to False) is
> > enclosed in brackets & a $ sign is appended at the end of the
> > expression like this
>
> > ([0-9]{2}|[0-9]{3})$
>
> > then 216 correctly evaluates to True (& so does 16).
>
> > What I couldn't figure out is the logic behind the expression when it
> > is wrapped in brackets & a $ sign is appended at the end! Can someone
> > please explain me this? What more work does the edited
> > ValidationExpression do to make 216 evaluate to True?
>
> > I am aware that $ means the end of a string.
>
> > Thanks,
>
> > Ron
>
> Check out the Expresso application. =A0Written in dot.net and has a GUI fo=
r
> developing regex. =A0Lots of examples of expressions built in and it will
> generate code in both C# and VB.Net. =A0Been using it since dot.net v.0.
>
> LS- Hide quoted text -
>
> - Show quoted text -

Sorry to say, friends, but I don't want an alternate/easier expression
or examples. Rather I would like to UNDERSTAND the LOGIC behind why

[0-9]{2}|[0-9]{3}

evaluates 216 to False & why

([0-9]{2}|[0-9]{3})$

evaluates 216 to True?

Thanks,

Ron

Re: RegExp Again!

am 29.03.2008 21:19:33 von Courtney

"RN1" wrote in message
news:06e408d8-33d0-46d6-8eb4-174314054e51@h11g2000prf.google groups.com...
On Mar 28, 7:46 pm, "Lloyd Sheen" wrote:
> "RN1" wrote in message
>
> news:e4dbd317-a37d-4632-8786-d05581b0199b@n58g2000hsf.google groups.com...
>
>
>
>
>
> > Using Regular Expression, I want to ensure that users enter either a 2-
> > digit or a 3-digit whole number in a TextBox. This is how I framed the
> > ValidationExpression in the RegularExpressionValidator:
>
> > ------------------------------------------------------------ ---------------­-----
> >
> > > > Display="dynamic" ErrorMessage="Invalid Text"
> > ValidationExpression="[0-9]{3}|[0-9]{2}" runat="server"/>
> > ------------------------------------------------------------ ---------------­-----
>
> > Suppose a user enters 16 & 216 in the TextBox. As expected, both the
> > numbers return True but if I just reverse the ValidationExpression
> > i.e. change the ValidationExpression from
>
> > [0-9]{3}|[0-9]{2}
>
> > to
>
> > [0-9]{2}|[0-9]{3}
>
> > & then input 16 & 216 in the TextBox, 16 correctly evaluates to True
> > but 216 strangely evaluates to False!
>
> > After a plethora of trial & error methods, I realized that if the
> > second ValidationExpression (the one which evaluates 216 to False) is
> > enclosed in brackets & a $ sign is appended at the end of the
> > expression like this
>
> > ([0-9]{2}|[0-9]{3})$
>
> > then 216 correctly evaluates to True (& so does 16).
>
> > What I couldn't figure out is the logic behind the expression when it
> > is wrapped in brackets & a $ sign is appended at the end! Can someone
> > please explain me this? What more work does the edited
> > ValidationExpression do to make 216 evaluate to True?
>
> > I am aware that $ means the end of a string.
>
> > Thanks,
>
> > Ron
>
> Check out the Expresso application. Written in dot.net and has a GUI for
> developing regex. Lots of examples of expressions built in and it will
> generate code in both C# and VB.Net. Been using it since dot.net v.0.
>
> LS- Hide quoted text -
>
> - Show quoted text -

Sorry to say, friends, but I don't want an alternate/easier expression
or examples. Rather I would like to UNDERSTAND the LOGIC behind why

[0-9]{2}|[0-9]{3}

evaluates 216 to False & why

([0-9]{2}|[0-9]{3})$

evaluates 216 to True?

Thanks,

Ron

Ok using Expresso I see the following explanation:
' Imports System.Text.RegularExpressions

' Regular expression built for Visual Basic on: Sat, Mar 29, 2008, 04:16:52
PM
' Using Expresso Version: 3.0.2717, http://www.ultrapico.com
'
' A description of the regular expression:
'
' Select from 2 alternatives
' Any character in this class: [0-9], exactly 2 repetitions
' [0-9]{3}
' Any character in this class: [0-9], exactly 3 repetitions
' Return
' New line
'
'


([0-9]{2}|[0-9]{3})$


' Imports System.Text.RegularExpressions

' Regular expression built for Visual Basic on: Sat, Mar 29, 2008, 04:17:37
PM
' Using Expresso Version: 3.0.2717, http://www.ultrapico.com
'
' A description of the regular expression:
'
' [1]: A numbered capture group. [[0-9]{2}|[0-9]{3}]
' Select from 2 alternatives
' Any character in this class: [0-9], exactly 2 repetitions
' Any character in this class: [0-9], exactly 3 repetitions
' $
' End of line or string
' Return
' New line
'
'
Not sure if this is what you are looking for.

LS