일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- keyboardEvent
- textContent
- Dom
- Empty
- TypingEffect
- css:position
- javascript
- js
- innerText
- Event
- Review
- nodeValue
- node
- node.js
- ES5
- CSS
- dotenv
- es6
- modal
- a11y
- addEventListener
- HTML
- innerHTML
- beforeinput
- yet
- for loop
- react
- keyup
- Temporal dead zone
- UI
- Today
- Total
the murmurous sea
RegExp 본문
1. object (In JavaScript, regular expressions are also objects. )
2. is used for matching text with a pattern.
3. Regular expressions are patterns used to match character combinations in strings.
4. used with the exec() and test() methods of RegExp,
and with the match(), matchAll(), replace(), replaceAll(), search(), and split() methods of String.
5. Starting with ECMAScript 6, new RegExp(/ab+c/, 'i'), when the first argument is a RegExp and the second flags argument is present. A new RegExp from the arguments is created instead.
6. When using the constructor function, the normal string escape rules (preceding special characters with \ when included in a string) are necessary.
Syntax
There are two ways to create a RegExp object: a literal notation and a constructor.
1. The literal notation's parameters are enclosed between slashes and do not use quotation marks.
: Results in compilation of the regular expression when the expression is evaluated.
: Use literal notation when the regular expression will remain constant.
For example, if you use literal notation to construct a regular expression used in a loop, the regular expression won't be recompiled on each iteration.
2. The constructor function's parameters are not enclosed between slashes but do use quotation marks.
: For example, new RegExp('ab+c') results in runtime compilation of the regular expression.
: Use the constructor function when you know the regular expression pattern will be changing, or you don't know the pattern and are getting it from another source, such as user input.
/ab+c/i
new RegExp(/ab+c/, 'i') // literal notation
new RegExp('ab+c', 'i') // constructor
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
'#dev > undone Q' 카테고리의 다른 글
flex vs. grid (0) | 2020.07.17 |
---|---|
async vs. fetch (0) | 2020.06.25 |
JS ES6: Promise vs. Async await (0) | 2020.06.15 |
JS ES5: strict / non-strict(sloppy) mode (0) | 2020.06.10 |
JS OOP: (0) | 2020.06.09 |