1

in one of some configs files i have the next RegEx: /\.story\.jsx?$/ It's select all files with 'story.jsx' in name, but i also want ignore file if his name has 'template' word. How can i do this with single RegEx: if (.story.jsx && !template) ?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Volodymyr Humeniuk
  • 3,411
  • 9
  • 35
  • 70
  • Your current positive match regex already ignores the negative case, right? – Tim Biegeleisen Nov 08 '18 at 09:52
  • 2
    `/^(?!.*template).*\.story\.jsx?$/` - all you need is to add the negative lookahead check at the start of the string and then consume all chars there are before your string suffix. – Wiktor Stribiżew Nov 08 '18 at 09:54
  • @TimBiegeleisen no, it's does not ignore anything, its just select all files with .story.js in name, but i want also ignore files .template.story.js with the same RegEx – Volodymyr Humeniuk Nov 08 '18 at 09:54
  • `(?!.*template)` supplied above by Wiktor ignores anything with the word template in it. Its a negative look ahead. – user50619 Nov 08 '18 at 09:56
  • @WiktorStribiżew thanks, this is work! – Volodymyr Humeniuk Nov 08 '18 at 09:57
  • After the [comment above](https://stackoverflow.com/questions/53205186/regex-if-file-name-not-contain-specific-word#comment93298649_53205186), I changed the dupe reason, and your regex can be precised as `/^(?!.*\.template\.story\.jsx?$).*\.story\.jsx?$/` – Wiktor Stribiżew Nov 08 '18 at 09:57

0 Answers0