Meaning of regular expressions like - \d , \D, ^ , $ etc
这些表达是什么意思?在哪里可以了解它们的用法?
1 2 3 4 5 6 7 8 9 10 11 12 13 | \\d \\D \\s \\S \\w \\W \\t \ ^ $ \ | etc.. |
我需要使用
从
The caret ‘^’ and the dollar sign ‘$’ are metacharacters that
respectively match the empty string at the beginning and end of a
line. The symbols ‘\<’ and ‘>’ match the empty string at the
beginning and end of a word. The symbol ‘\b’ matches the empty
string at either edge of a word, and ‘\B’ matches the empty string
provided it is not at an edge of a word. (The interpretation of
‘word’ depends on the locale and implementation: these are all
extensions.)
从类Perl的正则表达式:
The escape sequences ‘\d’, ‘\s’ and ‘\w’ represent any decimal
digit, space character and ‘word’ character (letter, digit or
underscore in the current locale: in UTF-8 mode only ASCII letters
and digits are considered) respectively, and their upper-case
versions represent their negation. Vertical tab was not regarded
as a space character in a ‘C’ locale before PCRE 8.34 (included in
R 3.0.3). Sequences ‘\h’, ‘\v’, ‘\H’ and ‘\V’ match horizontal
and vertical space or the negation. (In UTF-8 mode, these do
match non-ASCII Unicode code points.)
请注意,反斜杠通常需要在r输入中加倍/保护,例如,您将使用
来自
Backslash is used to start an escape sequence inside character
constants. Escaping a character not in the following table is an
error.newline
carriage return
\t tab
正如上面其他人的评论,如果您第一次开始使用正则表达式,可能需要更多的帮助。StackOverflow(指向非站点资源的链接)的主题有点离题,但是在gsubfn包概述的底部有一些指向正则表达式资源的链接。或者谷歌"正则表达式教程"…