const regex = /.*images\/(?!cached).*/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('.*images\\\/(?!cached).*', 'g')
const str = `./images/logos/partners/mastergen.png
./images/logos/partners/highland.png
./images/logos/partners/charollais.png
./images/logos/partners/grasstec.png
./images/logos/partners/stabiliser.png
./images/logos/services
./images/logos/services/farmpay-icon.png
./images/cached
./images/cached/.DS_Store
./images/cached/logo-farmpay-black.png
./images/cached/logo-green-text.svg
./images/cached/readme.md
./images/cached/logo-green-icon.svg
./images/cached/logo-green-icon.png
./images/cached/logo-farmpay-white.png
./images/cached/logo-white-text.svg
./images/cached/logo-green.png
./images/user
./images/user/.DS_Store
./images/user/shield.svg
./images/user/shield-error.svg
./images/user/test-delete.png
./images/user/locked-avatar.png
./images/user/unknown-avatar.png
./images/listing-photo-guides
./images/listing-photo-guides/goats
./images/listing-photo-guides/goats/.DS_Store
./images/listing-photo-guides/goats/bad
./images/listing-photo-guides/goats/bad/1.png
./images/listing-photo-guides/goats/good
./images/listing-photo-guides/goats/good/1.png
./images/listing-photo-guides/pigs
./images/listing-photo-guides/pigs/.DS_Store
./images/listing-photo-guides/pigs/bad
./images/listing-photo-guides/pigs/bad/2.png
./images/listing-photo-guides/pigs/bad/1.png
./images/listing-photo-guides/pigs/good
./images/listing-photo-guides/pigs/good/2.png
./images/listing-photo-guides/pigs/good/1.png
./images/listing-photo-guides/.DS_Store
./images/listing-photo-guides/dairy-cattle
./images/listing-photo-guides/dairy-cattle/.DS_Store
images/listing-photo-guides/dairy-cattle/bad
./images/listing-photo-guides/dairy-cattle/bad/2.png
./images/listing-photo-guides/dairy-cattle/bad/3.png
./images/listing-photo-guides/dairy-cattle/bad/1.png
./images/listing-photo-guides/dairy-cattle/good
./images/listing-photo-guides/dairy-cattle/good/2.png
./images/listing-photo-guides/dairy-cattle/good/3.png
./images/listing-photo-guides/dairy-cattle/good/1.png
./images/listing-photo-guides/sheep
./images/listing-photo-guides/sheep/.DS_Store
./images/listing-photo-guides/sheep/bad
./images/listing-photo-guides/sheep/bad/4.png
./images/listing-photo-guides/sheep/bad/2.png
./images/listing-photo-guides/sheep/bad/3.png
./images/listing-photo-guides/sheep/bad/1.png
./images/listing-photo-guides/sheep/good
./images/listing-photo-guides/sheep/good/4.png
./images/listing-photo-guides/sheep/good/2.png
./images/listing-photo-guides/sheep/good/3.png
./images/listing-photo-guides/sheep/good/1.png
./images/listing-photo-guides/breeding-cattle
./images/listing-photo-guides/breeding-cattle/.DS_Store
./images/listing-photo-guides/breeding-cattle/bad
./images/listing-photo-guides/breeding-cattle/bad/4.png
./images/listing-photo-guides/breeding-cattle/bad/2.png
./images/listing-photo-guides/breeding-cattle/bad/3.png
./images/listing-photo-guides/breeding-cattle/bad/1.png
./images/listing-photo-guides/breeding-cattle/good
./images/listing-photo-guides/breeding-cattle/good/4.png
./images/listing-photo-guides/breeding-cattle/good/2.png
./images/listing-photo-guides/breeding-cattle/good/3.png
./images/listing-photo-guides/breeding-cattle/good/1.png
./images/listing-photo-guides/store-cattle
./images/listing-photo-guides/store-cattle/.DS_Store
./images/listing-photo-guides/store-cattle/bad
./images/listing-photo-guides/store-cattle/bad/2.png
./images/listing-photo-guides/store-cattle/bad/1.png
./images/listing-photo-guides/store-cattle/good
./images/listing-photo-guides/store-cattle/good/2.png
./images/listing-photo-guides/store-cattle/good/1.png
./images/backgrounds
./images/backgrounds/auctions.jpg
./images/backgrounds/family-cows.jpg
./images/backgrounds/tablet-livestock.jpg
./images/backgrounds/dna-strand.jpg
./images/backgrounds/apps.jpg
./images/backgrounds/.DS_Store
./images/backgrounds/handshake-livestock.jpg
./images/backgrounds/cows.jpg
./images/backgrounds/sheep.jpg
./images/backgrounds/premium-seller.jpg
./images/backgrounds/handshake-trade.jpg
./images/backgrounds/haulage-trailer.jpg
./images/backgrounds/uk-map.png
./images/backgrounds/vet.jpg
./images/team
./images/team/kate-jones.jpg
./images/team/michelle-shores.jpg
./images/team/dan-luff.jpg
./images/team/.DS_Store
./images/team/sam-scott.jpg
./images/team/andrew-loftus.jpg
./images/team/ben-stanley.jpg
./images/team/rosie-hetherington.jpg
./images/team/derek-lewis.jpg
./images/team/peter-ellis.jpg
./images/team/andrew-huxham.jpg
./images/team/alex-crooks.jpg
./images/team/bertie-steggles.jpg
./images/team/jamie-mcinnes.jpg
./images/team/patrick-bidwell.jpg
./images/team/dave-rose.jpg
./images/team/becky-smith.jpg
./images/team/andrew-connon.jpg
./images/team/karen-johnson.jpg
./scss
./scss/config
./scss/config/_variables.scss
./scss/vendor.scss
./scss/components
./scss/components/blog.scss
./scss/components/button.scss
./scss/components/table.scss
./scss/components/forms.scss
./scss/components/layout.scss
./scss/components/tag.scss
./scss/components/tooltip.scss
./scss/components/typography.scss
./scss/components/animations.scss
./scss/components/utility.scss
./scss/components/loading.scss
./scss/app.scss
./native-app
./native-app/generated
./native-app/generated/.DS_Store
./native-app/generated/ios
./native-app/generated/ios/splash
./native-app/generated/ios/splash/Default-568h@2x~`;
// 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