1

Given these folder names:

locales/DE/en    
locales/FR/en
locales/US/en
locales/US/fr
public
test
[...]

I want to match everything EXCEPT the first 2 patterns. There are other folders in the root, and other subfolders in the locales folder. I really want to just exclude everything in locales/* EXCEPT locales/US

This works for locales but fails to include the other root folders.
/(locales)\/(US)/

Any thoughts?

Jamis Charles
  • 5,827
  • 8
  • 32
  • 42
  • 1
    If you allow everything, use `^.*$` and restrict it with a lookahead disallowing the `locales/(?:DE|FR)` at the beginning: [`/^(?!locales\/(?:DE|FR)).*$/`](https://regex101.com/r/vF1fZ3/3). – Wiktor Stribiżew Mar 02 '16 at 07:53

2 Answers2

4

To match anything EXCEPT locales/US, you can use negative lookahead:

/^(?!locales\/US).*/m

RegEx Demo

anubhava
  • 761,203
  • 64
  • 569
  • 643
1

You can use two regular expressions instead of cluttering it up in one. Below is an attempt:

my @folders =
  qw (locales/DE/en locales/FR/en locales/US/en locales/US/fr public test);

foreach (@folders) {
    if (/^locales/) {
        next if ( $_ !~ /^locales\/US/ ); # skip everything except locales/US
    }
    print $_,"\n";
}
Arunesh Singh
  • 3,489
  • 18
  • 26