const regex = /^[\s+-]?[^\s]+\s([^\s\n]+).*$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^[\\s+-]?[^\\s]+\\s([^\\s\\n]+).*$', 'gm')
const str = ` +883620946918182db5a277fc5e328fee3030ef79 src/dobot_cr_driver (8836209)
-8fc5c05835a246d7cb46952f748efec11fbf0075 src/onrobot_driver
b5704131f0e2964e4d051d5e6f6560917c2a1969 src/ros_camera
1ffdd69181389b14b7d6342f0c5bad3b45c5e32f src/ur_meta (1.1.5-315-g1ffdd69)
ec2beb65afd6be5373d1e21a86dd42a07e25b447 src/ur_official_driver (v2.0.0-4-gec2beb6)
883620946918182db5a277fc5e328fee3030ef79 src/dobot_cr_driver (8836209)
8fc5c05835a246d7cb46952f748efec11fbf0075 src/onrobot_driver (8fc5c05)
b5704131f0e2964e4d051d5e6f6560917c2a1969 src/ros_camera (heads/develop)
1ffdd69181389b14b7d6342f0c5bad3b45c5e32f src/ur_meta (1.1.5-315-g1ffdd69)
ec2beb65afd6be5373d1e21a86dd42a07e25b447 src/ur_official_driver (v2.0.0-4-gec2beb6)`;
// 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