const regex = /^(\+ *|- *)?((?!0+)\d*?|(?!0{2,})\d*?\.(?!0+)\d*?)('|")$|^(\+ *|- *)? *(?!0+)\d+?' *-? *(\d+?|\d*?\.\d*?)"$|^((\+ *|- *)?((?!0+)|0 )\d*? *(?!0+)\d+?\/(?!0+)\d+?('|"))$/mg;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(\\+ *|- *)?((?!0+)\\d*?|(?!0{2,})\\d*?\\.(?!0+)\\d*?)(\'|")$|^(\\+ *|- *)? *(?!0+)\\d+?\' *-? *(\\d+?|\\d*?\\.\\d*?)"$|^((\\+ *|- *)?((?!0+)|0 )\\d*? *(?!0+)\\d+?\\\/(?!0+)\\d+?(\'|"))$', 'mg')
const str = ` -
+
- x 20'-4"
+ 20'
- 20'
20'3"
20'-3"
20' - 40"
-20'-20"
20'00"
20.45"
20.45'
00.45'
00.45"
00"
00'
+20' - 0.45"
20' - .45"
.20'-4"
0.30'-4"
20'
20'P
20"
20"P
0.20'
.20'
a'
b"
- 20 1/2'
+ 20 22/128"
20 0/2"
20 00/12'
-1/2"
+ 1/2'
0/2"
00/22"
+ 01/2"
23 00/30'
23 12/03'
23 02/20"
0 2/3'
00 2/3'
- 11 2/3'
2 22'
2 22/03'
2 3/2
23 00/30
23 12/03
23 02/20
23/34"
23/23.4"
asf sf"
`;
// 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