When using the Javascrip regular expression, it is found that the contents of a particular string within a string can be taken according to a regular expression. To illustrate:
<! DOCTYPE html>functionCheck (email_address) {varRegex =/^ ([0-9a-za-z\-_\.] +) @ ([0-9a-z]+\. [A-z] {2,3} (\. [A-z] {2})?) $/G; if(Regex.test (email_address)) {varuser_name = Email_address.replace (Regex, "$" ); vardomain_name = Email_address.replace (Regex, "$" ); varalert_string = "The email address you entered is legal \ n \ nthe"; Alert_string+ = "User name:" + user_name + "\ n"; Alert_string+ = "Domain Name:" +domain_name; Window.alert (alert_string); return true; } Else{Window.alert ("The email address you entered is not valid" ); return false; } }</script>In the example, var user_name = Email_address.replace (Regex, "$"), and the user name in the email address is intercepted. "$" means ^ ([0-9a-za-z\-_\.] +)
"$" represents a group reference, which refers to the first set of strings that were previously matched;
JavaScript Regular Expression string.replace (regex, "$"), meaning of "$", and mailbox regular expression