On 01.09.2011 20:44, gaz Heyes wrote:
On 1 September 2011 17:25, Dmitry A. Soshnikov
<dmitry.soshni...@gmail.com <mailto:dmitry.soshni...@gmail.com>> wrote:
Though, you can give me your regexp you think fits better for
education article ;) Only of course it won't complicate the things
too much.
Slightly complicates matters I suppose :)
I use a syntax check combined with the following regex for variables:-
function isVariable(expression) {
var unicode = /\\u[0-9a-fA-F]{4}/,
variable = RegExp("^(?:[^\x00-\x7f\u2028\u2029]|[a-zA-Z_$]|" +
unicode.source + ")(?:[^\x00-\x7f\u2028\u2029]|[\\w$_]|" +
unicode.source + ")*$");
That's it -- while it perhaps perfectly correct, unfortunately it will
complicate the article which is without it too big :(
Anyway, I can use your regexp it for my scheme-on-coffee ;)
Dmitry.
return variable.test(expression);
}
isVariable('abc\\u0061aa');//true
isVariable('123');//false
isVariable('\\u0061');//true
isVariable('\\00');//false
isVariable('a/**/');//false
Variables are quite tricky to regex since they create a redos
condition by design, if you can find a hole in that regex then you can
probably pwn jsreg.
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/jsmentors@jsmentors.com/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/jsmentors@googlegroups.com/
To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/jsmentors@jsmentors.com/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/jsmentors@googlegroups.com/
To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com