-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregex.js
More file actions
29 lines (22 loc) · 860 Bytes
/
regex.js
File metadata and controls
29 lines (22 loc) · 860 Bytes
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
// Regex
let regexp = /t.[a-z]*t/;
let regexp = /E+/;
let crowd = 'P1P2P3P4P5P6CCCP7P8P9';
let findC = /C+/;
let matchedC = crowd.match(findC);
console.log(matchedC);
let repeatStr = "regex regex";
let repeatRegex = /(\w+)\s\1/;
repeatRegex.test(repeatStr);
"First Second".replace(/(\w+)\s(\w+)/, '$2 $1'); // "Second First"
let originalText = "I am good.";
let targetRegex = /good/;
let replaceText = "well, thank you";
let result = originalText.replace(targetRegex, replaceText);
function spinalCase(str) {
let regex = /\s+|_+/g;
str = str.replace(/([a-z])([A-Z])/g, '$1 $2');
// Find any lowercase letterfollowed by uppercase letter, and replace with the same divided by a space
//Return the string with all spaces and underscores replaced with dashes and then convert to all lowercase
return str.replace(regex, '-').toLowerCase();
}