New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

float-regex

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

float-regex

regular expression to match floating point numbers in javascript notation

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

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

Keywords

regex

FAQs

Package last updated on 17 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts