Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- JDBC
- custom hook
- type
- Debug
- IBM
- java api
- useEffect
- descendingOrder
- codewars
- react
- DB2
- manifest.json
- TABLESPACE
- codewar
- TypeScript
- react hook
- isSquare
Archives
- Today
- Total
taesik
string replace using regex 본문
function pigIt(str){
return str.replace(/(\w)(\w*)(\s|$)/g, "\$2\$1ay\$3")
}
function pigIt(str) {
return str.replace(/\w+/g, (w) => {
return w.slice(1) + w[0] + 'ay';
});
}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
String.prototype.replace() - JavaScript | MDN
The replace() method returns a new string with some or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function to be called for each match. If pattern is a string, onl
developer.mozilla.org
$ can be used in replacer function on .replace()
'functions and trick > typescript_javascript' 카테고리의 다른 글
| temp (0) | 2022.01.26 |
|---|---|
| is valid phone number (regex) (0) | 2022.01.26 |
| isValidIP (0) | 2022.01.26 |
| makes this string uppercasegives it sorted in alphabetical order by last name. (0) | 2022.01.25 |
| Sum of numbers from 0 to N (0) | 2022.01.25 |