Skip to content

Instantly share code, notes, and snippets.

@troZee
Created January 1, 2021 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troZee/5b68cabfb31ccf1aa14eeb29c30895f1 to your computer and use it in GitHub Desktop.
Save troZee/5b68cabfb31ccf1aa14eeb29c30895f1 to your computer and use it in GitHub Desktop.
regex for only positive price
const regex = /(^0[\,\.][0-9]{1,}$)|(^[1-9][0-9]{1,}$)|(^[0-9]$)|(^[1-9][0-9]{0,}[\,\.][0-9]{1,}$)/gm;
const str = `01
001
033
0000033
00000.2
00000000000000
01010101010
0000.0
aaa
???!!!!!
111%\$\$\$\$
100.255
10.25555
1.2
1335354.12
22
2
1
13353544366564547
0.22222298
0.2
0,2989080
6767676767676767677676767677676
0
0.22
123
`;
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}`);
});
}
@troZee
Copy link
Author

troZee commented Jan 1, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment