Regular Expression search in Sublime for all font-family: not preceded by an opening comment

孤街浪徒 提交于 2019-12-24 15:53:47

问题


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


来源:https://stackoverflow.com/questions/34354806/regular-expression-search-in-sublime-for-all-font-family-not-preceded-by-an-ope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!