Solved

What is the largest regular expression size?

Posted on 2004-09-20
12
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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|^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|^1FB.U82E.4|^1FB.U82K.4|^1FB.U83E.4|^1FB.U83K.4|^1FB.U83W.4|^1FB.U84E.4|^1FB.U84K.4|^1FB.U84W.4|^1FB.U85E.4|^1FB.U85K.4|^1FB.U85W.4|^1FD.U62E.4|^1FD.U62K.4|^1FD.U63E.4|^1FD.U63K.4|^1FD.U63W.4|^1FD.U64E.4|^1FD.U64K.4|^1FD.U64W.4|^1FD.U65E.4|^1FD.U65K.4|^1FD.U65W.4|^1FD.U71E.4|^1FD.U72E.4|^1FD.U72K.4|^1FD.U73E.4|^1FD.U73K.4|^1FD.U73W.4|^1FD.U74E.4|^1FD.U74K.4|^1FD.U74W.4|^1FD.U75E.4|^1FD.U75K.4|^1FD.U75W.4|^1FD.U82E.4|^1FD.U82K.4|^1FD.U83E.4|^1FD.U83K.4|^1FD.U83W.4|^1FD.U84E.4|^1FD.U84K.4|^1FD.U84W.4|^1FD.U85E.4|^1FD.U85K.4|^1FD.U85W.4|^1FM.U62E.4|^1FM.U62K.4|^1FM.U63E.4|^1FM.U63K.4|^1FM.U63W.4|^1FM.U64E.4|^1FM.U64K.4|^1FM.U64W.4|^1FM.U65E.4|^1FM.U65K.4|^1FM.U65W.4|^1FM.U71E.4|^1FM.U72E.4|^1FM.U72K.4|^1FM.U73E.4|^1FM.U73K.4|^1FM.U73W.4|^1FM.U74E.4|^1FM.U74K.4|^1FM.U74W.4|^1FM.U75E.4|^1FM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U72E.4|^2FT.U72K.4|^2FT.U73E.4|^2FT.U73K.4|^2FT.U73W.4|^2FT.U74E.4|^2FT.U74K.4|^2FT.U74W.4|^2FT.U75E.4|^2FT.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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

733 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