What does the underscore mean in the following regex?
在下面的regex中下划线是什么意思?
[a-zA-Z0-9_]
(a-zA-Z0-9_)
The _
seems to make no difference so I don't understand the purpose of it.
似乎没有什么区别,所以我不明白它的目的。
5 个解决方案
#1
47
It means to match the underscore character in addition to lowercase letters, uppercase letters, and numbers.
它意味着除了小写字母、大写字母和数字之外还要匹配下划线字符。
#2
68
The underscore means an underscore.
下划线表示下划线。
#3
15
It means the underscore is also matched.
这意味着下划线也被匹配。
#4
11
Regular expressions are documented in perlre. That's the place to check whenever you have a question about regular expressions. The Regular-Expressions.info site is very helpful too.
正则表达式被记录在perlre中。每当你有关于正则表达式的问题时,都可以在这里进行检查。信息网站也很有帮助。
To get you started, the thing you are looking at is called a "character class".
为了让您开始,您正在查看的内容被称为“角色类”。
#5
9
With the exception of character sequences ([.
, [:
, and [=
), range expressions (e.g., [a-z]
), and the circumflex in the beginning ([^
), every character inside a bracket expression means the character itself, just like that underscore.
除了字符序列([。(:,(=),范围表达式(例如,[a - z])和弯曲的开始([^),每个角色在括号表达式意味着字符本身,就像这样强调。
As a side note, that expression is commonly represented by \w
(word character, ignoring unicode and locale), and is commonly used to define the set of characters that are allowed to be used in variable names.
作为附带说明,该表达式通常以\w(字字符,忽略unicode和locale)表示,通常用于定义允许在变量名中使用的字符集。
#1
47
It means to match the underscore character in addition to lowercase letters, uppercase letters, and numbers.
它意味着除了小写字母、大写字母和数字之外还要匹配下划线字符。
#2
68
The underscore means an underscore.
下划线表示下划线。
#3
15
It means the underscore is also matched.
这意味着下划线也被匹配。
#4
11
Regular expressions are documented in perlre. That's the place to check whenever you have a question about regular expressions. The Regular-Expressions.info site is very helpful too.
正则表达式被记录在perlre中。每当你有关于正则表达式的问题时,都可以在这里进行检查。信息网站也很有帮助。
To get you started, the thing you are looking at is called a "character class".
为了让您开始,您正在查看的内容被称为“角色类”。
#5
9
With the exception of character sequences ([.
, [:
, and [=
), range expressions (e.g., [a-z]
), and the circumflex in the beginning ([^
), every character inside a bracket expression means the character itself, just like that underscore.
除了字符序列([。(:,(=),范围表达式(例如,[a - z])和弯曲的开始([^),每个角色在括号表达式意味着字符本身,就像这样强调。
As a side note, that expression is commonly represented by \w
(word character, ignoring unicode and locale), and is commonly used to define the set of characters that are allowed to be used in variable names.
作为附带说明,该表达式通常以\w(字字符,忽略unicode和locale)表示,通常用于定义允许在变量名中使用的字符集。