On 01.09.2011 20:44, gaz Heyes wrote:
On 1 September 2011 17:25, Dmitry A. Soshnikov <[email protected] <mailto:[email protected]>> 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/[email protected]/

To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

--
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to