开发者

RegExp in Xcode: exclude matches from result set?

开发者 https://www.devze.com 2023-01-24 13:06 出处:网络
Looking for proper regular expression syntax to use in Xcode’s \"Project Find\" to get all occurrences of \"nslog\" but not \"//nslog\". Can do eac开发者_开发百科h search independently but not sure h

Looking for proper regular expression syntax to use in Xcode’s "Project Find" to get all occurrences of "nslog" but not "//nslog". Can do eac开发者_开发百科h search independently but not sure how to "chain" them.


The normal way to say “does not follow” with regular expressions is using the (?<!...) construct. So it’s possible that

(?<!//)nslog

may work. It depends on which regex flavor the tool you’re using follows, which is something I don’t know. But it’s been an hour since you asked, and no one else has offered you any answers, so I figure it can’t hurt anything to try.

In case you cannot do lookbehind negations, a pattern that’s guaranteed to work anywhere is

[^/][^/]nslog

However, that does not mean the same thing as the previous pattern!

Instead of saying must not follow two slashes, it instead means there must be two non-slashes previous to that. These are actually different; consider the case of nslog occurring at the start of the line. The first pattern would succeed and the second one would fail.

Finally, if slash is used as a pattern delimiter — meaning, it surrounds and quotes the pattern — then you would have to do one of:

  1. Select an alternate pattern delimiter; for example, #(?<!//)nslog# if you are permitted to select an octothorpe as the quoting delimiter around your pattern.
  2. Backwhack any slashes used internally and induce LTS (Leaning Toothpick Syndrome); for example, (?<!\/\/)nslog.
  3. Use some form of numeric escape, such as \057 for octal or \x2F for hex; for example, (?<!\x2F\x2F)nslog.

Hope this helps.


The closest I think you can get is to search for e.g. [^/]NSLog - that will find NSLog but not //NSLog. Of course it will still find // NSLog, which may or may not work for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号