What does RegExp.$1 do

后端 未结 6 923
温柔的废话
温柔的废话 2021-02-02 13:34

I have come across a piece of code in JScript:

RegExp.$1

Does anybody know what it does?

If I output it on its own, I get nothing not e

6条回答
  •  终归单人心
    2021-02-02 14:02

    These work in conjunction with capturing parentheses. For example, /(foo)/ matches and remembers 'foo' in "foo bar." The matched substring can be recalled from the resulting array's elements [1], ..., [n] or from the predefined RegExp object's properties $1, ..., $9.

    In your example, the $1 refers to the match made by (.+)

    See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp

提交回复
热议问题