0

I'm trying to do some code refactoring and as I'm doing quite a lot I'm using WebStorm's regex find in files to see which files still need refactoring.

I know this (?:^|(?=[^']).\b)(this.user|this.isVatRegistered|showStatsInNet)\b will show all files with one of those bits of code in.

And according to this post: Match string that doesn't contain a specific word ^(?!.*UserMixin).*$ should do a negative look ahead to match only when that word doesn't exist.

My problem is I don't know how to combine them. Would someone be able to provide some guidance please?

I've tried combining like so: (?:^|(?=[^']).\b)(?!.*UserMixin)(this.user|this.isVatRegistered|showStatsInNet)\b but to no avail.

TL;DR How do I match on X number of words only when another word isn't present?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
webnoob
  • 15,747
  • 13
  • 83
  • 165

1 Answers1

1

You have to work with a negative lookahead then try to match those sub-strings:

\A(?![\d\D]*?UserMixin)[\d\D]*?\b(?:this\.(?:user|isVatRegistered)|showStatsInNet)\b

This would be time consuming though since there are two [\d\D]*? occurrences that will move the cursor character by character to the end of file content.

revo
  • 47,783
  • 14
  • 74
  • 117