What does the _ in [a-zA-Z0-9_] mean?

前端 未结 5 2072
天命终不由人
天命终不由人 2021-02-18 12:58

What does the underscore mean in the following regex?

[a-zA-Z0-9_]

The _ seems to make no difference so I don\'t understand the purpose

5条回答
  •  耶瑟儿~
    2021-02-18 13:26

    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.

    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.

提交回复
热议问题