开发者

What's the meaning of the regex? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or开发者_JAVA技巧 rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

Can anybody point it out?

  1. /^([a-zA-Z]+)/
  2. /\d|M|H/
  3. RegExp.$1


1.

/^([a-zA-Z]+)/

^             # match the start of the input string
(             # start capture group 1
  [a-zA-Z]+   #   match one or more from the set {a..z,A..Z} 
)             # end capture group 1

2.

/\d|M|H/

\d  # match a digit: {0..9}
|   # OR
M   # match the literal 'M'
|   # OR
H   # match the literal 'H'

which, as @Tim suggested in the comments, could better be written as: [\dMH]

3.

RegExp.$1 is probably not a regex (at least, it can't match anything). It's likely a language construct.


That means:

  1. /^([a-zA-Z]+)/ - it must starts with any alphabet
  2. /\d|M|H/ - it can be any digits, M or H
  3. RegExp.$1 - First argument of the Regex
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜