const regex = /\[img.*\].*photobucket.*(.jpg)\[\/img.*\]/gi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\[img.*\\].*photobucket.*(.jpg)\\[\\\/img.*\\]', 'gi')
const str = `Connecting rod fitted to prevent steering tie rod from cranking:
[url=http://s557.photobucket.com/user/realboss7669/media/F707F408-829F-48B9-9AED-BB57CEFF96C0_zpslwioah0z.jpg.html:jaeyh8wg][img:jaeyh8wg]http://i557.photobucket.com/albums/ss16/realboss7669/F707F408-829F-48B9-9AED-BB57CEFF96C0_zpslwioah0z.jpg[/img:jaeyh8wg][/url:jaeyh8wg]
From the rear:
[url=http://s557.photobucket.com/user/realboss7669/media/05AE0DB2-83FD-4B2C-9FDA-E3257DFEB832_zpsc6cfuqwi.jpg.html:jaeyh8wg][img:jaeyh8wg]http://i557.photobucket.com/albums/ss16/realboss7669/05AE0DB2-83FD-4B2C-9FDA-E3257DFEB832_zpsc6cfuqwi.jpg~original[/img:jaeyh8wg][/url:jaeyh8wg]
Steering damper mounts finished - without the connecting rod the damper would get bent:
[url=http://s557.photobucket.com/user/realboss7669/media/C85A0F5D-413D-4779-9F09-BD43BB798238_zpse8s6dxyu.jpg.html:jaeyh8wg][img:jaeyh8wg]http://i557.photobucket.com/albums/ss16/realboss7669/C85A0F5D-413D-4779-9F09-BD43BB798238_zpse8s6dxyu.jpg[/img:jaeyh8wg][/url:jaeyh8wg]
<!-- s8) --><img src="{SMILIES_PATH}/icon_cool.gif" alt="8)" title="Cool" /><!-- s8) -->`;
// 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