-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
74 lines (65 loc) · 1.39 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const str = `hello
010-1234-5678
https://www.omdbapi.com/?apikey=7035c60c&s=frozen
The quick brown fox jumps over the lazy dog.
abbcccdddd
http://localhost:1234
동해물과 백두산이 마르고 닳도록 _
`
// console.log(str.match(/\.$/gim));
//^ab, ab$
console.log(
str.match(/d$/gm),
str.match(/^t/gim)
);
// . , a|b, ab?
console.log(
str.match(/./g),
str.match(/h..p/g),
str.match(/fox|dog/g),
str.match(/https/g),
str.match(/https?/g),
str.match(/https?/g)
);
// {3}, {3,}, {3,5}
console.log(
str.match(/d{2}/g),
str.match(/d{2,}/g),
str.match(/d{3,5}/g),
str.match(/\w{2,3}/g),
str.match(/\b\w{2,3}\b/g)
);
// [abc], [a-z], [A-Z], [0-9], [가-힣]
console.log(
str.match(/[fox]/g),
str.match(/[가-힣]/g),
);
// \w, \b, \d, \s
console.log(
str.match(/\w/g),
str.match(/\b/g),
str.match(/\bf\w{1,}/g),
str.match(/\d/g),
str.match(/\d{1,}/g),
str.match(/\s/g),
);
const h= ` the hello world !
`
console.log(
h.replace(/\s/g, '')
);
// 앞쪽일치(?=), 뒷쪽일치(?<=)
const str2 = `hello
010-1234-5678
https://www.omdbapi.com/?apikey=7035c60c&s=frozen
The quick brown fox jumps over the lazy dog.
abbcccdddd
http://localhost:1234
동해물과 백두산이 마르고 닳도록 _
`
console.log(
str2.match(/.{1,}(?=\@)/g),
str2.match(/(?<=\@).{1,}/g)
);