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:
- Select an alternate pattern delimiter; for example,
#(?<!//)nslog#
if you are permitted to select an octothorpe as the quoting delimiter around your pattern. - Backwhack any slashes used internally and induce LTS (Leaning Toothpick Syndrome); for example,
(?<!\/\/)nslog
. - 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.
精彩评论