tags:

views:

71

answers:

3

Can someone maybe help me with this regex? I am using Javascript and classic ASP.

checkxls = checkxls.match(/'.*?', '.*?', '.*?', '.*?', '.*?', '.*?', '.*?', '.*?', '.*?', '.*?', '.*?', '.*?', '.*?', '.*?';/ig)

I need to match this pattern exactly.

I am looking for a more elegant way of doing this.

+5  A: 

You can use a negative character class to avoid unnecessary backtracking:

/'[^']*'(?:, '[^']*'){13};/g

You can also drop the case-insensitive flags since there are no letters in your regular expression. This might give a small performance improvement.

Mark Byers
Thanks mark, I will remove the i
Gerald Ferreira
Hi mark any idea how I would do the same thing but just look for this pattern?('2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15'),it is basically the same pattern but just with a starting bracket and closing bracket
Gerald Ferreira
+3  A: 
/('', ){13}'';/ig
spender
This works for me thanks spender!
Gerald Ferreira
checkxls.match(/('.*?', ){13}'.*?';/ig); <<< like this
Gerald Ferreira
You don't need the `//i` flag.
Mark Byers
A: 
/(?:'[^']*', ){13}'[^']*';/g
Ken Redler