const regex = /\b(H )(\d+(?:\.\d+)?)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\b(H )(\\d+(?:\\.\\d+)?)', 'gm')
const str = `var str = "m 0.05291667,1.7345817 h 0.16018 V 0.05291667 H 1.4943367 v 0.56054601 l -0.16015,0.16017899 0.16015,0.16012501 V 1.4943397 H 0.69354668 V 1.2541247 H 1.2540967 V 1.0138577 L 1.0939467,0.90175268 H 0.69354668 v -0.240215 H 1.0939467 l 0.16015,-0.128138 V 0.29313166 H 0.45330668 V 1.7345817 H 1.6544867"
`;
// 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