Regex

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

Guest

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

Guest

Hi,

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

Any other idea?
Thanks,
Emilia.
 
G

Guest

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

Guest

Thanks a lot for your help!
Yes, you were right. The problem was with the string. Now it is working!!!
 

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

Regex in C# 4
Converting Regular expression match 5
Regex references 3
Regex help 1
Defining Strings using Dim or Const 3
Help with Regex 1
Regular Expression for URL 4
Problem with RegEx and matches 2

Top