JS Regular expression

Source: Internet
Author: User

1. Match any number in front of REM in a string similar to 12rem or 12.32rem

var xx = "Font-size:12rem;width:12.33rem;height:200rem;";

Xx.match (/(\d+) + (? =rem\b) | ( \d+\.) \d+ (=rem\b)/g);

Results: ["12", "12.33", "200"]

Description: A regular expression with/begins with a/g ending that represents a global match, \d represents a number, (\d+) indicates that the number repeats one or more times, and (? =rem\b) represents the front portion of a word (except REM) that matches a rem ending (\d+\.) The \d+ matches the integer digits with the decimal digits as any number of decimals.

2. Replace color: #fff或者color: #FFF, or color:white; for color: #000;

var yy = "color: #fff; Width:20rem;height:33rem;color: #FFF; overflow:hidden;color:white;";

Yy.replace (/color: #fff |color: #FFF |color:white/g, "color: #000");

Result: "COLOR: #000; Width:20rem;height:33rem;color: #000; Overflow:hidden;color: #000;"

3. Matches the preceding number part of a string that ends in. xhtml

var zz = "E:/android/projects/xxt/epub/1.xhtml";

var tt = "e:/android/projects/xxt/epub/12.xhtml";

Zz.match (/\d+ (=.xhtml$)/g) Result: ["1"]

Tt.match (/\d+ (=.xhtml$)/g) Result: ["12"]

Description:. xhtml$ represents a string that ends in XHTML, (? =.xhtml$) that matches the preceding part of the word (except. xhtml) at the end of XHTML.

JS 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.