Link to home
Start Free TrialLog in
Avatar of chriskchan
chriskchan

asked on

What is the largest regular expression size?

Say you declare a regular expression like:

var regMatch = new RegExp(sString);

What is the largest size that sString can be?  If I have a search pattern that is 2855 characters long, i get an "java.lang.ArrayIndexOutOfBoundsException: 20" error.  Is there a limit?  And is there a way to get around it?

Thanks,

Chris
Avatar of Zyloch
Zyloch
Flag of United States of America image

Hi chriskchan,

What code are you using exactly to make it overflow?

Regards,
Zyloch
Avatar of chriskchan
chriskchan

ASKER

Hi Zyloch,

The sString that I am putting in looks something like this "^1FB.U62E.4|^1FB.U62K.4|^1FB.U63E.4|^1FB.U63K.4|^1FB.U63W.4|^1FB.U64E.4|^1FB.U64K.4" but it goes on for a long time.  It is overflowing right at the line for declaring the regexp.

Chris
Doesn't seem to be a limit. I took your line and copied it over and over again until the string was a bit over 100,000 and while IE took its sweet time loading, it still didn't produce an error. Also, ArrayIndexOufOfBoundsExceptions isn't an error usually produced in Javascript. #1, javasript errors don't have java.lang. Second of all, Javascript doesn't produce ArrayIndexOutOfBoundsExceptions like Java does.

You can try putting / and / at the beginning and end of sString but shouldn't make much difference.

It may be in the rest of your code. Can you post that?

Regards...
Your regular expression looks remarkable inefficient.
It seems to be:

^1FB.U6[some digit][some letters].4

What possible values are you looking for for some digit or some letter?
Whoops, you're right, it's failing on the next line when it's doing the regular expression test.  So I'm getting the outofbounds exception on:

bRetVal = !regMatch.test(sVIN);

where sVIN is a string "1FMZU62K14ZA67457".

The full sString that makes up the regMatch regular expression is "^1FB.U62E.4|^1FB.U62K.4|^1FB.U63E.4|^1FB.U63K.4|^1FB.U63W.4|^1FB.U64E.4|^1FB.U64K.4|^1FB.U64W.4|^1FB.U65E.4|^1FB.U65K.4|^1FB.U65W.4|^1FB.U71E.4|^1FB.U72E.4|^1FB.U72K.4|^1FB.U73E.4|^1FB.U73K.4|^1FB.U73W.4|^1FB.U74E.4|^1FB.U74K.4|^1FB.U74W.4|^1FB.U75E.4|^1FB.U75K.4|^1FB.U75W.4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3FT.U64E.4|^3FT.U64K.4|^3FT.U64W.4|^3FT.U65E.4|^3FT.U65K.4|^3FT.U65W.4|^3FT.U71E.4|^3FT.U72E.4|^3FT.U72K.4|^3FT.U73E.4|^3FT.U73K.4|^3FT.U73W.4|^3FT.U74E.4|^3FT.U74K.4|^3FT.U74W.4|^3FT.U75E.4|^3FT.U75K.4|^3FT.U75W.4|^3FT.U82E.4|^3FT.U82K.4|^3FT.U83E.4|^3FT.U83K.4|^3FT.U83W.4|^3FT.U84E.4|^3FT.U84K.4|^3FT.U84W.4|^3FT.U85E.4|^3FT.U85K.4|^3FT.U85W.4"
StormyWaters,

The regular expression is for checking invalid VIN numbers, so the order and letters are very important.

Chris
Put the VIN numbers in an array then loop through the array.
Hmm so I guess there's no way around it huh?  Is there a limitation to the regexp .test method?
ASKER CERTIFIED SOLUTION
Avatar of StormyWaters
StormyWaters
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Interesting, thanks StormyWaters, I'll check that out.  That would simplify things a lot :).

Chris