Regexp Backslash - GNU Emacs Manual says that \<
matches at the beginning of a word, \>
matches at the end of a word, and \b
matches a word boundary. \b
is just as in other non-Emacs regular expressions. But it seems that \<
and \>
are particular to Emacs regular expressions. Are there cases where \<
and \>
are needed instead of \b
? For instance, \bword\b
would match the same as \<word\>
would, and the only difference is that the latter is more readable.
相关问题
- Symbol's function definition is void: declare-
- Improve converting string to readable urls
- How can I set the SVN password with Emacs 23.1 bui
- Regex to match charset
- Emacs shell: save commit message
相关文章
- Optimization techniques for backtracking regex imp
- ess-rdired: I get this error “no ESS process is as
- Regex to check for new line
- Allow only 2 decimal points entry to a textbox usi
- Emacs/xterm color annoyance on Linux
- Comparing speed of non-matching regexp
- Regular expression to get URL in string swift with
- 请问如何删除之前和之后的非字母中文单字
You can get unexpected results if you assume they behave the same..
What can \< and > that \b can do?
The answer is that
\<
and\>
are explicit... This end of a word! and only this end!\b
is general.... Either end of a word will match...GNU Operators * Word Operators
output
It looks to me like
\<.*?\>
would match only series of word characters, while\b.*?\b
would match either series of word characters or a series non-word characters, since it can also accept the end of a word, and then the beginning of one. If you force the expression between the two to be a word, they do indeed act the same.Of course, you could replicate the behavior of
\<
and\>
with\b\w
and\w\b
. So I guess the answer is that yes, it's mostly for readability. Then again, isn't that what most escape characters in regular expression are for?