const regex = /([\d]*)(.|,)[\d](e|E)[\d]+/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('([\\d]*)(.|,)[\\d](e|E)[\\d]+', 'gm')
const str = `Valid floating points:
1
+1
-1
65
+65
-65
5.2
5,2
5.225
5,225
985.225
985,225
985.
,225
+5.2
+5,2
+5.225
+5,225
+985.225
+985,225
+985.
+,225
-5.2
-5,2
-5.225
-5,225
-985.225
-985,225
-985.
-,225
5.2E3
5.2e3
+5.2e3
-5.2e3
5,2E3
5,2e3
-5,2e3
+5,2e3
5.2e112
+5.2e112245
-5.2e99999
5,2e112
-5,2e112245
+5,2e99999
5.2e+3
+5.2e+3
-5.2e+3
5,2e-3
-5,2e-3
+5,2e-3
5.e3
5.e+3
+5.e+3
-5.e+3
5,e-3
-5,e-3
+5,e-3
,225e123
+,225e123
-,225e123
.225e123
+.225e123
-.225e123
Not floating points
,
,
,
.
.
.
.e
,e
.e2
,e2
,225e
+,225e
-,225e
.225e
+.225e
-.225e`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions