这个正则表达式意味着什么/ ^ [a-z] {1} [a-z0-9 _] {3,13} $ /

时间:2014-06-24 11:10:48

标签: regex

有人可以详细说明以下正则表达式:

/^[a-z]{1}[a-z0-9_]{3,13}$/

并提供一些满足此正则表达式的示例字符串?

6 个答案:

答案 0 :(得分:5)

  • ^锚点断言我们位于字符串的开头
  • [a-z]{1}匹配一个小写字母。 {1}是不需要的。
  • [a-z0-9_]{3,13}匹配3到13个字符。在不区分大小写的模式下,在许多引擎中,它可以由\w{3,13}
  • 替换
  • $锚点断言我们位于字符串的末尾

样本匹配

abcd
a_000
a_blue_tree

请参阅demo

一般答案"此正则表达式意味着什么?

  1. 您可以使用“regex101”等工具来使用正则表达式。右侧窗格按令牌解释令牌。
  2. 有几个解释工具基于相同的原始Perl库,例如this one,其中一个答案基于。
  3. 最终答案可以在 Mastering Regular Expressions,3rd Ed。和几个优秀的在线教程中找到,包括本网站上的regex FAQ

答案 1 :(得分:2)

Check Explanation Here

NODE                     EXPLANATION
  ^                        the beginning of the string
  [a-z]{1}                 any character of: 'a' to 'z' (1 times)
  [a-z0-9_]{3,13}          any character of: 'a' to 'z', '0' to '9',
                           '_' (between 3 and 13 times (matching the
                           most amount possible))
  $                        before an optional \n, and the end of the
                           string

答案 2 :(得分:1)

说明:/^[a-z]{1}[a-z0-9_]{3,13}$/

  • ^ - 断言字符串的开头

  • [a-z]{1}完全匹配a-z中的一个字符。

  • [a-z0-9_]{3,13}匹配a-z或0-9中的任何字符,但长度范围必须介于3到13之间。

  • $结束

Example

答案 3 :(得分:1)

这意味着: 以一个(^)小写字符({1})开始([a-z]),然后至少继续三个({3,),但最多为13个13}来自一组小写字符,下划线和数字([a-z0-9_])的字符。之后,预计行结束($)。

a000满足条件

答案 4 :(得分:0)

匹配以a-z开头的字符串,后跟字符集a-z0-9_中的3到13个字符。

有许多online tools将解释/详述正则表达式的含义以及测试它们。

答案 5 :(得分:0)

Assert position at the beginning of the string «^»
Match a single character in the range between “a” and “z” «[a-z]{1}»
   Exactly 1 times «{1}»
Match a single character present in the list below «[a-z0-9_]{3,13}»
   Between 3 and 13 times, as many times as possible, giving back as needed (greedy) «{3,13}»
   A character in the range between “a” and “z” «a-z»
   A character in the range between “0” and “9” «0-9»
   The character “_” «_»
Assert position at the end of the string (or before the line break at the end of the string, if any) «$»

使用RegexBuddy生成