Solved

What is the largest regular expression size?

Posted on 2004-09-20
12
348 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:chriskchan
  • 5
  • 3
  • 2
12 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 12106943
Hi chriskchan,

What code are you using exactly to make it overflow?

Regards,
Zyloch
0
 

Author Comment

by:chriskchan
ID: 12107054
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
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12107092
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...
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 13

Expert Comment

by:StormyWaters
ID: 12107171
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?
0
 

Author Comment

by:chriskchan
ID: 12107173
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|^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T.U75K.4|^2FT.U75W.4|^2FT.U82E.4|^2FT.U82K.4|^2FT.U83E.4|^2FT.U83K.4|^2FT.U83W.4|^2FT.U84E.4|^2FT.U84K.4|^2FT.U84W.4|^2FT.U85E.4|^2FT.U85K.4|^2FT.U85W.4|^3FT.U62E.4|^3FT.U62K.4|^3FT.U63E.4|^3FT.U63K.4|^3FT.U63W.4|^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"
0
 

Author Comment

by:chriskchan
ID: 12107199
StormyWaters,

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

Chris
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12107204
Put the VIN numbers in an array then loop through the array.
0
 

Author Comment

by:chriskchan
ID: 12107257
Hmm so I guess there's no way around it huh?  Is there a limitation to the regexp .test method?
0
 
LVL 13

Accepted Solution

by:
StormyWaters earned 125 total points
ID: 12107294
Couldn't you use this:
http://www.mathnotes.com/aw_IDnumber.html

to test for valid VINs?
0
 

Author Comment

by:chriskchan
ID: 12107316
Interesting, thanks StormyWaters, I'll check that out.  That would simplify things a lot :).

Chris
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Where is java script information saved? 2 52
Simple Total function not working 8 32
Checkout Page Input Field not aligned 1 23
key press alert 2 18
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question