Regular Expression search in Sublime for all font-

2019-08-07 05:41发布

问题:

I have to remove a lot of font-family: declarations from my website, they are hundreds and I have replaced most of them with the same line, only commented (ex: /* font-family: "Segoe UI","Helvetica","Arial"; */).

Now, if I could only search for the un-commented ones to find the few that are left. My first atempt clearly demonstrates I do not fully understand regular expressions:

^(?!(?:/*)).*\s*."font-family:"."*"

The syntax is Boost (but only a subpart of it, as the replacement is PCRE-style).

回答1:

You have almost done it yourself, I just fixed your tempered greedy token:

^(?:(?!/\*).)*\s*font-family:.*

See regex demo

Regex explanation:

  • ^ - start of line (in S&R in SublimeText)
  • (?:(?!/\*).)* - a tempered greedy token matching 0 or more characters other than a newline up to the first /* (to force a . to match newlines, add (?s) before ^)
  • \s* - zero or more whitespace symbols
  • font-family:- a literal sequence of font-family:
  • .* - 0 or more characters other than newline