Xcode 中的 RegExp:从结果集中排除匹配项? [英] RegExp in Xcode: exclude matches from result set?
问题描述
在 Xcode 的项目查找"中寻找正确的正则表达式语法,以获取所有出现的nslog"而不是//nslog".可以独立进行每个搜索,但不确定如何链接"它们.
用正则表达式说不遵循"的正常方式是使用 (?<!...)
结构.所以有可能
可能工作.这取决于您使用的工具遵循哪种正则表达式,这是我不知道的.但是自从你问起已经一个小时了,没有其他人给你任何答案,所以我认为尝试没有任何伤害.
如果你不能做lookbehind negations,一个保证在任何地方都有效的模式是
[^/][^/]nslog
然而,这并不意味着与之前的模式相同!
不是说一定不能跟在两个斜杠后面,而是意味着前面必须有两个非斜杠.这些实际上是不同的;考虑 nslog
出现在行首的情况.第一个模式会成功,第二个会失败.
最后,如果斜线被用作模式分隔符——意思是,它包围并引用模式——那么你必须执行以下操作之一:
- 选择一个备用模式分隔符;例如,
#(?<!//)nslog#
,如果您可以选择八索作为模式周围的引用分隔符. - 对内部使用的任何斜线进行反击并诱发 LTS(倾斜牙签综合症);例如,
(?.
- 使用某种形式的数字转义,例如
\057
表示八进制或\x2F
表示十六进制;例如,(?.
希望这会有所帮助.
Looking for proper regular expression syntax to use in Xcode’s "Project Find" to get all occurrences of "nslog" but not "//nslog". Can do each 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.
这篇关于Xcode 中的 RegExp:从结果集中排除匹配项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!