Help with Regex

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

Guest

Hi,
I have this regex

^[a-zA-Z] + (([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$

How can I get it to check the length of the string up to 25 characters? so
that any string more than 25 characters will not be matched.

Thanks
 
Chris said:
I have this regex

^[a-zA-Z] + (([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$

How can I get it to check the length of the string up to 25 characters? so
that any string more than 25 characters will not be matched.

The simplest way would just be to have a separate (non-regex) check:

if (foo.Length > 25 && [do the regex match here])
{
....
}
 
Jon said:
I have this regex

^[a-zA-Z] + (([\'\,\.\-][a-zA-Z])?[a-zA-Z]*)*$

How can I get it to check the length of the string up to 25 characters? so
that any string more than 25 characters will not be matched.

The simplest way would just be to have a separate (non-regex) check:

if (foo.Length > 25 && [do the regex match here])
{
...
}

I believe this should be "foo.Length <= 25 && [regex match]", logically.

Apart from that, this is not only the simplest but also the only useful
way, really, because regular expressions don't have much support for
length checking. The only construct vaguely associated with that would be
{n,m}, which is a quantifier - a{2,7} would match a string of 2 to 7 a's.
But in your expression there's no place where a quantifier like that could
restrict the match length of the whole expression.


Oliver Sturm
 
Oliver Sturm said:
The simplest way would just be to have a separate (non-regex) check:

if (foo.Length > 25 && [do the regex match here])
{
...
}

I believe this should be "foo.Length <= 25 && [regex match]", logically.

Oops, of course :)
 

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

Help with this 2
Regular expression 4
Regex wiseguy or girl 2
regex validate rangename 8
Regular Expressions question on whitespace 2
RegEx help 3
Regex problems 2
Help with Regex 1

Back
Top