PC Review


Reply
Thread Tools Rate Thread

RegEx - easy question

 
 
=?Utf-8?B?YmF5bG9y?=
Guest
Posts: n/a
 
      23rd Jun 2005
How do i tell if a string obeys a regular expression?

i thought i knew but then i tried to verify that a string was a certain
length...

Regex.IsMatch("1234", @"\w{1,3}")

This returns true and i don't want it to!

i understand that it found *a* match - "123" matched \w{3}. But i don't care
if some substring matched, i want to know if the entire value matched

Help?

-baylor
 
Reply With Quote
 
 
 
 
rossum
Guest
Posts: n/a
 
      23rd Jun 2005
On Thu, 23 Jun 2005 13:13:04 -0700, baylor
<(E-Mail Removed)> wrote:

>How do i tell if a string obeys a regular expression?
>
>i thought i knew but then i tried to verify that a string was a certain
>length...
>
> Regex.IsMatch("1234", @"\w{1,3}")
>
>This returns true and i don't want it to!
>
>i understand that it found *a* match - "123" matched \w{3}. But i don't care
>if some substring matched, i want to know if the entire value matched
>
>Help?
>
>-baylor


If you want to match the whole string then put '^' at the start and
'$' at the end of your regular expression. They match
start-of-string/line and end-of-string/line respectively. Your
example would become @"^\w{1,3}$"

rossum


The ultimate truth is that there is no ultimate truth
 
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 question (easy?) sb Microsoft Dot NET 5 23rd Sep 2006 03:10 PM
Easy RegEx question Alan Silver Microsoft ASP .NET 4 20th Jul 2005 10:04 PM
new user with easy question? not easy for me speakeztruth Microsoft Excel New Users 4 3rd Jun 2005 10:40 PM
Send To - EASY QUESTION / Task Bar - Another EASY ? Mike Microsoft Windows 2000 Applications 3 24th May 2004 08:55 PM
C# Regex Help - should be an easy one Oren Liebermann Microsoft C# .NET 1 28th Apr 2004 10:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:55 PM.