Skip to content

Instantly share code, notes, and snippets.

@kangax
Created November 22, 2008 06:21
Show Gist options
  • Select an option

  • Save kangax/27759 to your computer and use it in GitHub Desktop.

Select an option

Save kangax/27759 to your computer and use it in GitHub Desktop.
var wsp = '(\\u0020|\\u0009|\\u000D|\\u000A)';
var digit = '\\d';
var digit_sequence = '(' + digit + '+' + ')';
var sign = '[-+]';
var exponent = '[eE]' + sign + '?' + digit_sequence;
var fractional_constant =
'(' +
digit_sequence + '?' + '\\.' + digit_sequence +
'|' +
digit_sequence + '\\.' +
')';
var floating_point_constant =
'(' +
fractional_constant + exponent + '?' +
'|' +
digit_sequence + exponent +
')';
var integer_constant = digit_sequence;
var comma = ',';
var comma_wsp =
'(' +
'(' + wsp + '+' + comma + '?' + wsp + '*' + ')' +
'|' +
'(' + comma + wsp + '*' + ')' +
')';
var number =
'(' +
sign + '?' + integer_constant +
'|' +
sign + '?' + floating_point_constant +
')';
new RegExp('^'+number+'$').test('5e'); // matches (but should not match)
/*
list-of-points:
wsp* coordinate-pairs? wsp*
coordinate-pairs:
coordinate-pair
| coordinate-pair comma-wsp coordinate-pairs
coordinate-pair:
coordinate comma-wsp coordinate
coordinate:
number
number:
sign? integer-constant
| sign? floating-point-constant
comma-wsp:
(wsp+ comma? wsp*) | (comma wsp*)
comma:
","
integer-constant:
digit-sequence
floating-point-constant:
fractional-constant exponent?
| digit-sequence exponent
fractional-constant:
digit-sequence? "." digit-sequence
| digit-sequence "."
exponent:
( "e" | "E" ) sign? digit-sequence
sign:
"+" | "-"
digit-sequence:
digit
| digit digit-sequence
digit:
"0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
wsp:
(#x20 | #x9 | #xD | #xA)+
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment