float-regex
regular expression to match floating point numbers in javascript notation
Last updated 6 years ago by substack .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install float-regex 
SYNC missed versions from official npm registry.

float-regex

regular expression for real floating point values in javascript notation:

module.exports = /[-+]?(?:\d*\.?\d+|\d+\.?\d*)(?:[eE][-+]?\d+)?/;

does not match:

  • +/- Infinity
  • NaN

example

anchor a string:

var anchor = RegExp('^' + require('float-regex').source + '$');
console.log(anchor.test('1.23e24')); // true
console.log(anchor.test('1.23e24.55')); // false

capture floats:

var freg = require('float-regex').source;
var capture = RegExp('\\b(' + freg + ')\\b', 'g');
var str = '1.2  555    beep boop 4.2.1.5 66.2e99  22.54e23 qrs2';
console.log(str.match(capture));

which prints:

[ '1.2', '555', '4.2', '.1', '.5', '66.2e99', '22.54e23' ]

install

With npm do:

npm install float-regex

license

MIT

Current Tags

  • 1.0.0                                ...           latest (6 years ago)

1 Versions

  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 4
This Month 6
Last Day 0
Last Week 2
Last Month 17
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |