在正则表达式中,\w* 是什么意思? [英] In regex, what does \w* mean?

查看:342
本文介绍了在正则表达式中,\w* 是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Python 中.r^[\w*]$

In Python. r^[\w*]$

这是什么意思?

推荐答案

快速回答: 匹配由单个字符组成的字符串,其中该字符是字母数字(字母、数字)和下划线(_) 或星号 (*).

Quick answer: Match a string consisting of a single character, where that character is alphanumeric (letters, numbers) an underscore (_) or an asterisk (*).

详情:

  • \w"表示任何单词字符",通常表示字母数字(字母、数字,不分大小写)加上下划线 (_)
  • ^"锚定"到字符串的开头,将$"锚定"到字符串的末尾,这意味着,在这种情况下,匹配必须从字符串的开头开始,并在字符串的结尾结束.
  • [] 表示字符类,意思是匹配字符类中包含的任何字符".
  • The "\w" means "any word character" which usually means alphanumeric (letters, numbers, regardless of case) plus underscore (_)
  • The "^" "anchors" to the beginning of a string, and the "$" "anchors" To the end of a string, which means that, in this case, the match must start at the beginning of a string and end at the end of the string.
  • The [] means a character class, which means "match any character contained in the character class".

还值得一提的是,字符串的正常引用和转义规则使得输入正则表达式变得非常困难(所有反斜杠都需要用额外的反斜杠转义),因此在 Python 中有一个特殊的符号,它有自己的允许正确解释所有反斜杠的特殊引用规则,这就是开头的r"的用途.

It is also worth mentioning that normal quoting and escaping rules for strings make it very difficult to enter regular expressions (all the backslashes would need to be escaped with additional backslashes), so in Python there is a special notation which has its own special quoting rules that allow for all of the backslashes to be interpreted properly, and that is what the "r" at the beginning is for.

注意:通常星号 (*) 表示0 个或多个前一个事物",但在上面的示例中,它不是 有这个意思,因为星号在字符类的里面,所以它失去了它的特殊性".

Note: Normally an asterisk (*) means "0 or more of the previous thing" but in the example above, it does not have that meaning, since the asterisk is inside of the character class, so it loses its "special-ness".

有关 Python 中正则表达式的更多信息,两个官方参考是re 模块,正则表达式HOWTO.

For more information on regular expressions in Python, the two official references are the re module, the Regular Expression HOWTO.

这篇关于在正则表达式中,\w* 是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆