如何使用 iPhone SDK 使 RegexKitLite 生成所有匹配项的列表 +/- 并返回周围的文本
我想创建一个正则表达式,它将根据以下条件进行匹配和返回:
1)我有用户输入的 N 个搜索词
2)我有一个文本正文。
3)我想返回用户输入的所有搜索词的所有出现次数以及周围上下文的列表。我认为 (\w+\W+){,4}(", ")(\W+\w+){,4} 可能有效。
4)我根本不知道如何使用RegexKitLite。我是否调用 RegexKitLite 类?或者它是否以某种方式连接到 NSString ?
I'd like to create a regular expression that will match and return based on the following criteria:
1) I have N search terms entered by a user
2) I have a body of text.
3) I want to return a list of all the occurrences of all the search terms entered by the user plus surrounding context. I think (\w+\W+){,4}(", ")(\W+\w+){,4} might work.
4) I don't know how to use RegexKitLite at all. Do I invoke a RegexKitLite class? or does it interface into NSString somehow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RegexKitLite 定义了 类别。要获取与模式匹配的子字符串数组,请使用
componentsMatchedByRegex:
,如文档的“创建每个匹配的数组”部分所示。RegexKitLite defines a category on NSString. To get an array of substrings matching a pattern, use
componentsMatchedByRegex:
, as shown in the "Creating an Array of Every Match" section of the documentation.