开发者

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

开发者 https://www.devze.com 2023-02-04 09:55 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or开发者_JAVA技巧 rhetorical andcannot be reasonably answered in its current form.
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

精彩评论

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