const regex = new RegExp('(?<![\\u4E00-\\u9FAF\\u3040-\\u3096\\u30A1-\\u30FA\\uFF66-\\uFF9D\\u31F0-\\u31FF])(?<!\\d)(?<!\\d\\.)(\\d+(?:\\.\\d+)?m2)', 'gm')
const str = `"110.94m2・129.24m2";
--> 110.94m2 and 129.24m2
"81.95m2(24.78坪)、うち2階車庫8.9m2"
--> 81.95m2
"80.93m2(登記)"
--> 80.93m2
"93.42m2・93.85m2(登記)"
--> 93.42m2 and 93.85m2
"81.82m2(実測)"
--> 81.82m2
"81.82m2(実測)、うち1階車庫7.82m2"
--> 81.82m2
"90.11m2(実測)、うち1階車庫8.07m2"
--> 90.11m2`;
// 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