Skip to content

Instantly share code, notes, and snippets.

@xyzdata
Last active July 4, 2017 08:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xyzdata/dede93edfd8536cba25d67d863bfe6ac to your computer and use it in GitHub Desktop.
Save xyzdata/dede93edfd8536cba25d67d863bfe6ac to your computer and use it in GitHub Desktop.
regex

regex

    
//regex

const regex = /^(\w+)\:\/\/([^\/]+)\/(.*)$/;

let url = `https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Regular_Expressions`;

regex.test(url);

// true

regex.exec(url);
/*

(4) 
[
    "https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Regular_Expressions",
    "https",
    "developer.mozilla.org",
    "zh-CN/docs/Web/JavaScript/Guide/Regular_Expressions", 
    {
        index: 0, 
        input: "https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Regular_Expressions"
    }
]

0:"https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Regular_Expressions"
1:"https"
2:"developer.mozilla.org"
3:"zh-CN/docs/Web/JavaScript/Guide/Regular_Expressions"
index:0
input:"https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Regular_Expressions"
length:4

*/

https://regexper.com/#%2F%5E(%5Cw%2B)%5C%3A%5C%2F%5C%2F(%5B%5E%5C%2F%5D%2B)%5C%2F(.*)%24%2F

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Regular_Expressions

@xyzdata
Copy link
Author

xyzdata commented Jul 4, 2017

new window url
window location
regex-match-group

@xyzdata
Copy link
Author

xyzdata commented Jul 4, 2017

Regular_Expressions

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Regular_Expressions

https://regexper.com/#%2F%5E1%5B34578%5D%5Cd%7B9%7D%24%2F

1 开头,第二位 [34578] 组中的一个,\d === [0~9] 重复9次!

13788887777

14188887777

15188887777

16388887777

17788887777

18188887777
// phone: /^1[34578]\d{9}$/

let reg = /^1[34578]\d{9}$/;

reg.test("13377778888");
// true
reg.test("1337777888");
// false
reg.test("16337777888");
// false

image

const regex = /\w+\s/g;

// 替换成:

const regex  = new RegExp("\\w+\\s", "g");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment