Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How the $1Mutual 9 attribute in the js regular expression returns the result of a submatch

Shulou Source: shulou.com Published: 2022-06-02 03:45:59 09月19日 Update

This article is to share with you about how the $1 copyright 9 attribute in js regular expressions returns the result of a sub-match. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Function: $1 music 9 stores the matching results of the nine most recent regular expressions in the regular expression, which are arranged in the order in which the submatches appear.

Basic syntax RegExp.$n

Note: these properties are static, and RegExp is added to all uses except for the second parameter in replace that omits RegExp.

Case study: demo1

The code is as follows:

/ / create a string to match

Var objStr= "this is my cell phone number 13100000000"

/ / create a regular expression to match the mobile phone number

Var re=/ (13) (/ d) (/ d {8}) /; / / the regular expression can match the mobile phone number with the number 11 starting with 13 and the flag with () as the submatch.

[xss_clean] (objStr.replace (re, "$1 $2*")); / / replace the string according to the contents of the regular expression for privacy

/ / if the second sub-match result, that is, the third digit in the mobile phone number is less than or equal to 3, then the mobile phone number is the Unicom number, otherwise it is the number of other operators

If (RegExp.$2

Tags: Number mobile phone mobile phone number result regular expression this is character string phone number phone number attribute content operator operator three code parameter number Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Apple vpn Xiaomi Microsoft