Regular Expressions

R

RN1

$ in RegExp means the end of a string. So if the ValidationExpression
for a RegularExpressionValidator which validates a TextBox is "c
$" (without the double quotes), shouldn't input strings 'abc', '23pc',
'c9mccc' (all without the single quotes) evaluate to True BUT it
doesn't. In fact, these strings evaluate to False. Only the string
'c' (again without the single quotes) evaluates to True.

If I am not mistaken, "c$" means that any string (irrespective of its
length) will evaluate to True provided the last character in the
string is 'c' (without the single quotes). Or have I got it wrong? If
so, please correct me.

Thanks,

Ron
 
N

Nanda Lella[MSFT]

Hi Ron,

c$ means on 'c' and nothing else in the word.
If you are looking for any combination with a 'c', try something like
"^.*c.*$" (Without quotes)
"." represents any character. ^ = Start of the word, $ = end of the word.
You can also try removing the "^" from the above expression.

--------------------
From: RN1 <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Regular Expressions
Date: Thu, 27 Mar 2008 13:01:15 -0700 (PDT)
Organization: http://groups.google.com
Lines: 15
Message-ID:
NNTP-Posting-Host: 210.214.14.33
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1206648076 16849 127.0.0.1 (27 Mar 2008 20:01:16 GMT)
X-Complaints-To: (e-mail address removed)
NNTP-Posting-Date: Thu, 27 Mar 2008 20:01:16 +0000 (UTC)
Complaints-To: (e-mail address removed)
Injection-Info: t54g2000hsg.googlegroups.com; posting-host=210.214.14.33;
posting-account=PwKhagoAAAC2-o0UWffDXya8SmMhJMQ_
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;
Embedded Web Browser from: http://bsalsa.com/; .NET CLR 2.0.50727; .NET CLR
3.0.04506.30; COM+ 1.0.2204),gzip(gfe),gzip(gfe)
Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTFEEDS02.phx.gbl!msrtrans!
msrn-in!newshub.sdsu.edu!postnews.google.com!t54g2000hsg.googlegroups.com!no
t-for-mail
Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.dotnet.framework.aspnet:63081
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

$ in RegExp means the end of a string. So if the ValidationExpression
for a RegularExpressionValidator which validates a TextBox is "c
$" (without the double quotes), shouldn't input strings 'abc', '23pc',
'c9mccc' (all without the single quotes) evaluate to True BUT it
doesn't. In fact, these strings evaluate to False. Only the string
'c' (again without the single quotes) evaluates to True.

If I am not mistaken, "c$" means that any string (irrespective of its
length) will evaluate to True provided the last character in the
string is 'c' (without the single quotes). Or have I got it wrong? If
so, please correct me.

Thanks,

Ron

--

Thank You,
Nanda Lella,

This Posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Stan

$ in RegExp means the end of a string. So if the ValidationExpression
for a RegularExpressionValidator which validates a TextBox is "c
$" (without the double quotes), shouldn't input strings 'abc', '23pc',
'c9mccc' (all without the single quotes) evaluate to True BUT it
doesn't. In fact, these strings evaluate to False. Only the string
'c' (again without the single quotes) evaluates to True.

If I am not mistaken, "c$" means that any string (irrespective of its
length) will evaluate to True provided the last character in the
string is 'c' (without the single quotes). Or have I got it wrong? If
so, please correct me.

Thanks,

Ron

I believe the correct syntax for your requirement will be \w+[c]

You will also need a RequiredFieldValidator to prevent empty strings
from bypassing the expression evaluator.

BTW I don't know about the $ it doesn't feature in the RegExp
documentation that I've seen.
 
R

RN1

Try this site for help:

http://www.nregex.com/nregex/default.aspx

It gives some explanation on what the various characters mean as well
as a good tool to use for building a regular expression.

If you want any string ending in 'c', use ^.*c$

Thanks, my dear friends, for your inputs. I knew that "c$" would allow
only "c" & nothing else (i.e. the length of the string can be 1 & 1
only, not more than that) but in the article at
http://www.regular-expressions.info/anchors.html, it is stated that

-----------------------------------------
c$ matches c in abc
-----------------------------------------

(which is the 11th line in that article considering that the line
after the heading "Start of String and End of String Anchors" is the
1st line). Isn't that statement wrong? Yes...."c$" matches "c" in the
string "abc" but the string "abc" evaluates to False when the RegEx is
"c$". Or have I misinterpreted the term "matches" used in that
article?

That is what confused me.....

Ron
 
B

bruce barker

in a regular expression c$ will match abc (the capture will be c), but will
not with the RegularExpressionValidator. the RegularExpressionValidator
compares the controls value to the match, so it is the same as if your
expression was:

^c$$

to just check for an ending c with the RegularExpressionValidator you would
use:

.*c

which will be treated like

^.*c$


-- bruce (sqlwork.com)
 
J

Jesse Houwing

Hello RN1,
$ in RegExp means the end of a string. So if the ValidationExpression
for a RegularExpressionValidator which validates a TextBox is "c
$" (without the double quotes), shouldn't input strings 'abc', '23pc',
'c9mccc' (all without the single quotes) evaluate to True BUT it
doesn't. In fact, these strings evaluate to False. Only the string
'c' (again without the single quotes) evaluates to True.
If I am not mistaken, "c$" means that any string (irrespective of its
length) will evaluate to True provided the last character in the
string is 'c' (without the single quotes). Or have I got it wrong? If
so, please correct me.

Your regex is completely correct, just so you know, but there is a little
undocumented feature in the RagularExpressionValidator that puts a ^ and
a $ around the expression regardless of your wishes. os it actually tries
to evaluate this:

^c$$, which only accepts c as input.

The correct solution would be to make it

..*c

or

^.*c$

which will evaluate correctly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top