-2

I have a base classname form my icons, that is i-svg (this is the default icon size).

I have some modifiers to change the size, like i-svg--xs or i-svg--sm.

I need to find only the lines that don't use the modifiers classnames, that is just i-svg.

Excluded searches

class="someclass1 i-svg i-svg--xs someclass2"
class="someclass1 i-svg someclass2 i-svg--xs"
class="i-svg i-svg--xs"
class="i-svg i-svg--xs someclass1"
class="someclass1 i-svg i-svg--xs someclass2"

Included searches

class="someclass1 i-svg someclass2"
class="someclass1 i-svg"
class="i-svg someclass1"
class="i-svg"

What regular expression can I use for this search?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65

1 Answers1

0

the problem is that i-svg is a prefix of the string not allowed

You can do it in a 2 step find

  • Prepare a file with the following 2 regex strings
    class="[^"]*i-svg[^"]*"
    ^((?!i-svg--(xs|sm)).)*$
    
    Second regex based on SO answer
  • select the first regex: class="[^"]*i-svg[^"]*"
  • go to the file where you want to find
  • search for class="[^"]*i-svg[^"]*"
  • press Alt+Enter to select all matches and put focus in editor
  • go to other file and pick up: ^((?!i-svg--(xs|sm)).)*$ with Ctrl+C
  • go back to the file where you want to find
  • in find dialog press button: Find in Selection
  • replace regex with: ^((?!i-svg--(xs|sm)).)*$ with a Ctrl+V

Now only the class attributes with only i-svg are found.

rioV8
  • 24,506
  • 3
  • 32
  • 49