RegEx - easy question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 

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

Newbie question about Regex 8
Regex references 3
Regex Question 1
Regex pattern problem 2
regex validate rangename 8
Regex question (easy?) 5
Search STring in Regular Expression 4
Problem with RegEx and matches 2

Back
Top