float-regex
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/float-regex package

1.0.0 • Public • Published

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    808
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    808

Package Sidebar

Install

npm i float-regex

Weekly Downloads

624

Version

1.0.0

License

MIT

Last publish

Collaborators

  • nopersonsmodules