A search of the Internet for a good regex
floating point number grammar finds a lot of incomplete solutions.
Many, maybe even most, of them have numerous restrictions.
This one by Srinivas Gummadi
works pretty well.
It misses the .123
example, a fraction without leading integer, but still it is better than most.
First let’s have a look at the two grammars. If you are a regex
expert I’m sure you will have
no trouble seeing a floating point number expressed here.
If you are like me, maybe not so much.
const regex = /[-+]?[0-9]+[.]?[0-9]*([eE][-+]?[0-9]+)?/g;
const flags = 'g';
const exp = new apgExp(grammar, flags);
exp.exclude(['decimal', 'dot']);
console.log();
console.log('Compare apg-exp with RegExp for a floating point number.');
console.log();
console.log('RegExp grammar:');
console.log('/[-+]?[0-9]+[.]?[0-9]*([eE][-+]?[0-9]+)?/g');