【发布时间】:2013-06-05 21:25:50
【问题描述】:
我在iOS学习正则表达式,看到这个教程:http://www.raywenderlich.com/30288/nsregularexpression-tutorial-and-cheat-sheet
对于 \b 来说是这样的:
\b 匹配单词边界字符,例如空格和标点符号。 to\b 将匹配“to the moon”和“to!”中的“to”,但不会匹配“tomorrow”。 \b 对于“整个单词”类型匹配很方便。
和\s:
\s 匹配空格字符,例如空格、制表符和换行符。 hello\s 将匹配 "Well, hello there!" 中的 "hello"。
对此我有两个问题:
1)what is the difference between \s and \b? when to use which?
2)\b is handy for "whole word" type matching -> Don't understand the meaning..
在这两个方面需要一些指导。
【问题讨论】:
-
正则表达式中的断言类似于传统编程中的“IF”。
foo\b匹配 "foo" 如果它后跟一个非单词字符。 -
@thg435 首先感谢.. 有一个问题要问。什么是正则表达式中的断言?你有什么例子吗?
-
\b在您的问题中是一个断言。其他示例是诸如^、$和lookarounds 之类的锚点。
标签: ios regex nsregularexpression