正则表达式的含义--\\ d,\\ D,^,$等 [英] Meaning of regular expressions like - \\d , \\D, ^ , $ etc
问题描述
这些表达是什么意思?我在哪里可以了解它们的用法?
What do these expressions mean? Where can I learn about their usage?
\\d
\\D
\\s
\\S
\\w
\\W
\\t
\\n
^
$
\
| etc..
我需要使用stringr
软件包,我完全不知道如何使用它们.
I need to use the stringr
package and i have absolutely no idea how to use these .
推荐答案
在扩展正则表达式部分的?regexp
中:
插入符号"^"和美元符号"$"是 分别在一个字符串的开头和结尾匹配空字符串 线.符号"\<"和>"与 一个单词的开头和结尾.符号"\ b"与空白匹配 字词的任一边的字符串,并且'\ B'匹配空字符串 只要它不在单词的边缘. (对 单词"取决于语言环境和实现方式:这些都是 扩展程序.)
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的正则表达式:
转义序列"\ d","\ s"和"\ w"代表任意十进制 数字,空格字符和单词"字符(字母,数字或 在当前语言环境中下划线:在UTF-8模式下仅ASCII字母 和数字分别考虑)及其大写字母 版本代表它们的否定.不考虑垂直制表符 作为PCRE 8.34之前的"C"语言环境中的空格字符(包含在 R 3.0.3).序列"\ h","\ v","\ H"和"\ V"与水平匹配 和垂直空间或否定. (在UTF-8模式下, 匹配非ASCII Unicode代码点.)
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输入中加倍/保护,例如您将使用"\\h"
来匹配水平空间.
Note that backslashes usually need to be doubled/protected in R input, e.g. you would use "\\h"
to match horizontal space.
来自?Quotes
:
反斜杠用于在字符内部启动转义序列 常数.下表中未转义的字符是 错误.
\ n换行符
\ r回车符
\ t标签
Backslash is used to start an escape sequence inside character constants. Escaping a character not in the following table is an error.
\n newline
\r carriage return
\t tab
正如上面的其他评论所述,如果您是第一次开始使用正则表达式,则可能需要更多帮助.对于StackOverflow(链接到场外资源)来说,这有点偏离主题,但是
As others comment above, you may need a little more help if you're getting started with regular expressions for the first time. This is a little bit off-topic for StackOverflow (links to off-site resources), but there are some links to regular expression resources at the bottom of the gsubfn package overview. Or Google "regular expression tutorial" ...
这篇关于正则表达式的含义--\\ d,\\ D,^,$等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!