Cesar Zegarra
Cesar Zegarra

Reputation: 207

Regex Expression - Match test expressions for jasmine and karma

i need to create a regex expression that match all **.ts (typescripts files) but doesn't allow karma and jasmine test files: **.spec.ts and **.e2e.ts

Any help would be appreciated. :)

Upvotes: 1

Views: 1924

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626738

You may use

^(?!.*\.(e2e|spec)\.ts$).*\.ts$

Details:

  • ^ - start of string
  • (?!.*\.(e2e|spec)\.ts$) - the string cannot end with .e2e.ts nor with .spec.ts (this is a negative lookahead that fails the match if its pattern matches: any 0+ chars as many as possible (.*) up to the last . (\.), e2e or spec ((e2e|spec)), again a . and then ts at the end of the string ($))
  • .* - any 0+ chars as many as possible up to the last
  • \.ts - .ts literal char sequence
  • $ - end of string.

Upvotes: 1

Related Questions