Regex

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

Guest

Hi,

I have the following:

Dim mystring As String = "1.2 3 456 7........." That is 14818 long
Dim theReg As New Regex("( \d|-|\.|\s\d|\s-)+")
Dim theMatch As Match = theReg.Match(mystring)
If theMatch.Length = mystring.Length Then ...........

The problem is that theMatch.Length = 14766 and my string is 14818
Why is that? Is there any limitation on the Length of the Match?

Thanks in advance,
Emilia.
 
Don't think so.

The error got to be in the way the regular expression is formed
or that the data isn't exactly what you think it is. I'd start halfving
the string to nail down in what area of the string the matching doesn't
give the expected result.

I'd assume that a

Dim theReg As New Regex(".*")

would return a length of 14818.
 
Hi,

I have tried what you said, but the length of the match is 14766 instead of
14818.

Any other idea?
Thanks,
Emilia.
 
I duplicated your string in to a string with the length of 25600
and I got a match length back of 25600 using the matching anything regular
expression so there's obviously no built-in limitation there (at least with
reasonably long strings).

Used:
Dim theReg As New Regex(".*")
Got: theMatch.Length = 25600

This points at something not right with your data. Maybe you're
reading it in from a database or what not...

I'd verify the length again using just the String class' Length property
or some other independent means to verify actual length.


I'm not sure your reg exp. takes in to account any whitespace character
that might be in the data...
 
Thanks a lot for your help!
Yes, you were right. The problem was with the string. Now it is working!!!
 
Back
Top