const regex = /^.*\/api\/(?!.*(?:\.jpg|statistics)$).*$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^.*\\\/api\\\/(?!.*(?:\\.jpg|statistics)$).*$', 'gm')
const str = `http://localhost:8081/api/software-features
http://localhost:8081/api/user-groups/logged-user-group
http://localhost:8081/api/user-groups/%7B4D7E2585-32E3-4794-A0F3-4FE7D56D27AE%7D/permissions/system
http://localhost:8081/api/servers/%7B499C3279-CD5D-402E-A60B-6AE0B5A21EE0%7D/cameras
http://localhost:8081/api/servers/%7B499C3279-CD5D-402E-A60B-6AE0B5A21EE0%7D/cameras/0/streams/0/statistics
http://localhost:8081/api/servers/%7B499C3279-CD5D-402E-A60B-6AE0B5A21EE0%7D/cameras/0/streams/0/image-640x480.jpg`;
// 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