JavaScript Regular Expression String.Replace (regex, "$"), meaning of "$" and mailbox regular expression

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.