What does RegExp.$1 do

后端 未结 6 865
温柔的废话
温柔的废话 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

    $1 will return the first group that matches a regular expression.

    In your example, the value stored in $1 is whatever was matching .+

    The group is denoted by parenthesis and you can have multiples. Each saved group will just increment the digit with the $, i.e. $1, $2, $3...

    Example:

    If your input was __product[Version 12 Coupe] then $1 would contain Version 12 Coupe

提交回复
热议问题