const regex = /^-?(90|[0-8]?\d)(\.\d+)?, *-?(180|1[0-7]\d|\d?\d)(\.\d+)?$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^-?(90|[0-8]?\\d)(\\.\\d+)?, *-?(180|1[0-7]\\d|\\d?\\d)(\\.\\d+)?$', 'gm')
const str = `-23, 25
24.53525235, 23.45235
04, -23.234235
43.91343345, 143
4, -3
9.757674732245505, 84.58947867620736
23.234, - 23.4234
2342.43536, 34.324236
N23.43345, E32.6457
99.234, 12.324
6.325624, 43.34345.345
0, 1,2
0.342q0832, 1.2324
-23, 195
-23, 275
-23, 185`;
// 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