๐Ÿ“
til
  • TIL(Today I Learned)
  • javascript
    • value-number-string-boolean-null-undefined
    • primitive-reference
    • Hoisting
    • Prototypes in Javascript
    • this
    • prototype
    • ์ฝœ๋ฐฑํ•จ์ˆ˜ (Callback function)
    • ํ•จ์ˆ˜์˜ ํ˜ธ์ถœ
    • ์ž๋ฃŒ๊ตฌ์กฐ new keyword
    • closure
    • Promise
    • event-loop
    • array-object
    • ๊ฐ์ฒด
    • Arguments
    • higher order function
    • operators-function-control-flow
    • ๊ฐ์ฒด ์ƒ์„ฑ ํŒจํ„ด 3๊ฐ€์ง€
    • Javascript scopes
    • Functional Programming
    • Design Patterns
    • ๋ฐ์ดํ„ฐ ํƒ€์ž…
    • Object ๊ฐ์ฒด
    • ํ‘œ์ค€ ๋‚ด์žฅ ๊ฐ์ฒด์˜ ํ™•์žฅ
    • ์ฐธ์กฐ
    • ํ•จ์ˆ˜
    • ์ƒ์†(Inheritance)
    • this - 'this'๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํ•ด๋‹น ํ•จ์ˆ˜๋ฅผ '์–ด๋–ป๊ฒŒ' ์‹คํ–‰ํ•˜๋А๋ƒ์— ๋”ฐ๋ฅธ 4๊ฐ€์ง€ this ์ •์˜
    • ์ „์—ญ๊ฐ์ฒด(Global object)
    • ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ
    • The 'new' keyword - Object Creation in JavaScript
  • javascript-api
    • Number
      • Number.MAX_VALUE
      • Number.isInteger
      • Number.NEGATIVE_INFINITY
      • Number.isNaN()
      • Number.POSITIVE_INFINITY
      • Number.parseFloat
      • Number.EPSILON
      • number.toExponential
      • Number.MAX_SAFE_INTEGER
      • Number1 - ์ž์—ฐ์ˆ˜, ์ •์ˆ˜, 10์ง„์ˆ˜, 2์ง„์ˆ˜, ๋ถ€๋™์†Œ์ˆ˜์ , ์‹ค์ˆ˜
      • Number.isSafeInteger()
      • Number.MIN_VALUE
      • Number.parseInt
      • Number.NaN
      • Number.isFinite()
      • Number.MIN_SAFE_INTEGER
      • toFixed
    • string.split
    • String.fromCodePoint
    • string.trimEnd
    • string.padStart
    • string.@@iterator
    • String.fromCharCode
    • string.toUpperCase
    • string.codePointAt
    • string.toLowerCase()
    • string.toString
    • string.includes
    • string.replace()
    • string.charAt
    • String.lastIndexOf
    • string.slice
    • string.search
    • string.padEnd
    • string.substring
    • string.length
    • string.trim
    • string.localeCompare
    • String.indexOf
    • string.endsWith
    • string.valueOf
    • String.raw
    • string.matchAll()
    • string.repeat
    • string.match
    • String.prototype
    • string.startsWith
    • string.charCodeAt
    • string.trimStart
    • string.concat
    • string.toLocaleUpperCase()
    • string.toLocaleLowerCase
    • String
  • learn-node
    • debugger
    • Tip
  • schema-design
    • Database Schema Design
    • Database Schema Design
  • react
    • LifeCycle
    • redux
    • Context API
    • ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ์™€ ํด๋ž˜์Šค, ์–ด๋–ค ์ฐจ์ด๊ฐ€ ์กด์žฌํ• ๊นŒ?
    • Hooks๊ณผ useEffect ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ
    • Route
    • async wait ์‚ฌ์šฉํ•˜๊ธฐ
    • Hooks API Reference
    • context
    • npm uninstall ํ•˜๋Š”๋ฒ•
    • test ๋งŒ๋“ค๊ธฐ
  • tip
    • ํด๋ฆฐ์ฝ”๋“œ
    • BxSlider๋กœ ํ…์ŠคํŠธ ํ๋ฅด๋Š” ํšจ๊ณผ ๋งŒ๋“ค๊ธฐ
  • javascript30
    • Event Capture, Propagation, Bubbling and Once
    • Object and Arrays - Reference VS Copy
  • typescript
    • ์šฐ์•„ํ•œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ 2๋ถ€
    • The Basic Cheatsheet
    • TypeScript
    • Type Guards and Differnetiating Types
    • ์šฐ์•„ํ•œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ
    • Generics
  • git-from-the-hell
    • git
    • init-status-add-commit-log-stage-repository
    • log-diff
    • ๋จธ์ง€ ํ›„ branch ์‚ญ์ œํ•˜๊ธฐ
    • ์ง€์˜ฅ์—์„œ ์˜จ Git
    • reset-revert
    • develop branch ๋ฅผ pull ํ•˜๊ณ  ์‹ถ์„๋•Œ
  • conference-and-seminar
    • ๋ชจ๋˜ ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœํ™˜๊ฒฝ์˜ ์ดํ•ด
  • fire-base
    • Firebase .gitignore
  • vanillacoding
    • Data Structures
    • Sorting Algorithms - part 1
    • Promise
    • class
    • 04.quiz
    • 07.event-loop
    • Design Patterns
    • OOP (Object Oriented Programming)
  • etc
    • ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ฝ”๋“œ๋ฆฌ๋ทฐ
    • ์Šค์Šค๋กœ ๊ณต๋ถ€ํ•˜๋Š” ๋ฒ•
    • ๋ฐ”๋‹๋ผ์ฝ”๋”ฉ ์ˆ˜๊ฐ• ํ›„๊ธฐ
    • async ๊ณผ์ œ ํ›„๊ธฐ - ๋น„๋™๊ธฐ, ๋™๊ธฐ, ํด๋กœ์ €, ๋ฐฐ์—ด๊ณผ ๊ฐ์ฒด
    • ์œ ์šฉํ•œ ์‚ฌ์ดํŠธ
  • algorithm
    • The Supermarket Queue
    • Find the odd int
    • The Office III - Broken Photocopier
    • Directions Reduction
    • The Office II - Boredom Score
    • Divisible Sum Pairs
    • Codewars ์ด์šฉ์ž ์†”๋ฃจ์…˜ ๋ชจ์Œ
    • Shortest Word
    • find key
    • Two Sum
    • Simple Pig Latin
  • Book
    • the essence of object-orientation
      • ํƒ€์ž…๊ณผ ์ถ”์ƒํ™”
      • ๊ฐ์ฒด ์ง€๋„
      • ์ด์ƒํ•œ ๋‚˜๋ผ์˜ ๊ฐ์ฒด
      • ์ถ”์ƒํ™” ๊ธฐ๋ฒ•
      • 05. ์ฑ…์ž„๊ณผ ๋ฉ”์‹œ์ง€
      • 07.ํ•จ๊ป˜ ๋ชจ์œผ๊ธฐ
      • 04. ์—ญํ• , ์ฑ…์ž„, ํ˜‘๋ ฅ
      • ํ˜‘๋ ฅํ•˜๋Š” ๊ฐ์ฒด๋“ค์˜ ๊ณต๋™์ฒด
  • ecma-script2015
    • Object Literal Upgrades
    • default-parameter-template-literals-arrow-functions
    • spread-operator-rest-param
    • let-const-rest-parameter-spread-operator-destructuring
  • http
    • ์›น ๋ธŒ๋ผ์šฐ์ €์— URL์„ ์ž…๋ ฅํ–ˆ์„ ๋•Œ ์–ด๋–ป๊ฒŒ ์›น ํŽ˜์ด์ง€๊ฐ€ ๋ณด์—ฌ์งˆ๊นŒ?
  • jest
    • toThrow(error?)
  • data-structures
    • Data Structures
  • express
    • express generator
    • CORS
  • css-flexible-box-layout
    • flex ํ•ด๋ฒ„๋ ธ์ง€ ๋ญ์•ผ
  • git
    • Git
  • mongodb
    • MongoDB
  • markdown
    • use-markdown
  • cmder
    • cmd ๋ช…๋ น์–ด ๋ชจ์Œ
  • debug
    • trackClicksEx function error
  • npm
    • NPM TOKEN ์„ค์ •ํ•˜๊ธฐ
  • storybook
    • Storybook
  • sort
    • Sorting Algorithms - part 1
  • javascript-koans
    • Javascript Koans ์˜ค๋‹ต๋…ธํŠธ
  • rxjs
    • Rx.js
  • dom-elements
    • HTML Element
  • redux-toolkit
    • Redux Toolkit
  • github-actions
    • GitHub Actions
  • redux-middleware
    • redux middleware
  • rest
    • rest
  • css-rendering
    • ์ฝ”๋“œ ์Šคํ”ผ์ธ  - CSS Rendering 1ํšŒ์ฐจ 2/2
    • ์ฝ”๋“œ ์Šคํ”ผ์ธ  - CSS Rendering 1ํšŒ์ฐจ 1/2
  • you-dont-know-js
    • ํƒ€์ž…
  • server
    • # shutdown local server
  • semantic-versioning
    • Semantic Versioning 2.0.0
Powered by GitBook
On this page
  • Syntax
  • Parameters
  • return value
  • ์ถ”๊ฐ€ property
  • Description
  • Other methods
  • Examples
  • match() ์‚ฌ์šฉ
  • match()์™€ ํ•จ๊ป˜ g (๊ธ€๋กœ๋ฒŒ) ํ”Œ๋ž˜๊ทธ์™€ i(๋Œ€์†Œ๋ฌธ์ž ๋ฌด์‹œ) ํ”Œ๋ž˜๊ทธ ์‚ฌ์šฉํ•˜๊ธฐ
  • ๋งค๊ฐœ๋ณ€์ˆ˜ ์—†์ด match() ์‚ฌ์šฉํ•˜๊ธฐ
  • ๋น„ ์ •๊ทœํ‘œํ˜„์‹ ๊ฐ์ฒด๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์‚ฌ์šฉํ•˜๊ธฐ

Was this helpful?

  1. javascript-api

string.match

match() ๋ฉ”์„œ๋“œ๋Š” ๋ฌธ์ž์—ด์—์„œ ์ •๊ทœ์‹๊ณผ ๋งค์น˜๋˜๋Š” ๋ถ€๋ถ„์„ ๊ฒ€์ƒ‰ํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ›๋Š”๋‹ค.

const paragraph = 'Cats are the best';
const regex = /[A-Z]/g;
const found = paragraph.match(regex);

found; // ["C"]

Syntax

str.match(regexp)

Parameters

regexp

์ •๊ทœ์‹ ๊ฐ์ฒด์ด๋‹ค.

regexp๊ฐ€ ์ •๊ทœ์‹ ๊ฐ์ฒด๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ, new RegExp(regexp)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์•”์‹œ์ ์œผ๋กœ RegExp๋กœ ๋ณ€ํ™˜

์ธ์ˆ˜๋ฅผ ๋„˜๊ธฐ์ง€ ์•Š๊ณ  match() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋นˆ๋ฌธ์ž์—ด์„ ๊ฐ€์ง„ Array [''] ์ด ๋ฐ˜ํ™˜๋œ๋‹ค.

return value

global(g) flag์— ๋”ฐ๋ฅธ ๋‹ค๋ฅธ ๊ฒฐ๊ณผ์˜ Array, ๋งค์น˜๋˜๋Š” ๊ฒฐ๊ณผ๊ฐ€ ์—†๋‹ค๋ฉด null

  • g flag๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค๋ฉด, ์ „์ฒด ์ •๊ทœ ํ‘œํ˜„์‹๊ณผ ์ผ์น˜ํ•˜๋Š” ๋ชจ๋“  ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•˜์ง€๋งŒ, ์บก์ณ๊ทธ๋ฃน์€ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š๋Š”๋‹ค.

  • g flag๊ฐ€ ์—†๋‹ค๋ฉด ์ฒ˜์Œ ์ผ์น˜ํ•œ๊ฒƒ๊ณผ ๊ทธ์— ๋Œ€ํ•œ ์บก์ณ ๊ทธ๋ฃน์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. RegExp.exec() ์™€ ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ๋ฐ˜ํ™˜๋œ ์š”์†Œ๋Š” ๋‹ค์Œ ๐Ÿ‘‡ ์•„๋ž˜์™€ ๊ฐ™์€ ์ถ”๊ฐ€ ํ”„๋กœํผํ‹ฐ๋ฅผ ๊ฐ€์ง„๋‹ค.

global(g) flag

์ „์ฒด ํŒ๋ณ„, ์ฒ˜์Œ ์ผ์น˜์—์„œ ์ค‘๋‹จํ•˜์ง€ ์•Š๊ณ , ๋ฌธ์ž์—ด ์ „์ฒด๋ฅผ ํŒ๋ณ„ํ•œ๋‹ค.

์บก์ณ๋ง ๊ทธ๋ฃน(capturing group)

๊ด„ํ˜ธ๋ฅผ ๋‘˜๋Ÿฌ์‹ผ ์˜์—ญ์ด๋‹ค. ๊ฒฐ๊ณผ๊ฐ’์— ์ฒซ๋ฒˆ์งธ์—” ๋งค์นญ ๋ฌธ์ž์—ด์ด ๋“ค์–ด๊ฐ€๊ณ  ๊ทธ ํ›„๋ถ€ํ„ด ์บก์ณ๋ง ๊ทธ๋ฃน ์•ˆ์— ์žˆ๋Š” ๋ฌธ์ž์—ด์ด ์ฐจ๋ก€๋Œ€๋กœ ๋“ค์–ด๊ฐ„๋‹ค. ์บก์ณ๋ง ๊ทธ๋ฃน์„ ์‚ฌ์šฉํ•˜๋ฉด ํŒจํ„ด ์•ˆ์˜ ์›ํ•˜๋Š” ๋ถ€๋ถ„์„ ํŽธ๋ฆฌํ•˜๊ฒŒ ๋ถ„๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.

(?x)

x์— ๋งค์น˜ํ•˜๊ณ  ์œผ๋กœ ๋ช…๋ช…๋œ ์ด๋ฆ„์œผ๋กœ ๋งค์น˜๋œ ๋ฐ˜ํ™˜๊ฐ’์ด ๊ทธ๋ฃน ํ”„๋กœํผํ‹ฐ๋กœ ์ €์žฅ๋œ๋‹ค.

('<'๊ณผ '>')์— ๊ทธ๋ฃน๋ช…์€ ํ•„์ˆ˜๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด ์ „ํ™”๋ฒˆํ˜ธ์—์„œ ๋ฏธ๊ตญ์˜ ์ง€์—ญ ์ฝ”๋“œ๋ฅผ ๊บผ๋‚ผ ๋•Œ /((?\d\d\d))/์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ณ  ๊ฒฐ๊ณผ๋ฒˆํ˜ธ๋Š” matches.groups.area ์— ํ‘œ์‹œ๋œ๋‹ค.

const str = "Cats are the best. The cat will rule the universe.";
const regexpWithoutE = /\b[a-df-z]+\b/ig;
str.match(regexpWithoutE); // ["Cats", "cat", "will"]

const imageDescription = "์ด ์ด๋ฏธ์ง€์˜ ํ•ด์ƒ๋„๋Š” 1440ร—900 ์ด๋‹ค.";
const regexpSize = /([0-9]+)ร—([0-9]+)/;
const match = imageDescription.match(regexpSize); //  ["1440ร—900", "1440", "900", index: 12, input: "์ด ์ด๋ฏธ์ง€์˜ ํ•ด์ƒ๋„๋Š” 1440ร—900 ์ด๋‹ค.", groups: undefined]
// ์ฒซ๋ฒˆ์งธ๋Š” ๋งค์นญ ๋ฌธ์ž์—ด "1440ร—900"
// ์บก์ณ๋ง ๊ทธ๋ฃน ์•ˆ์— ์žˆ๋Š” ๋ฌธ์ž์—ด์ด ์ฐจ๋ก€๋กœ ๋“ค์–ด๊ฐ match[1]๋Š” "1440", match[2]๋Š” 900
let re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u;
const result = '2015-01-02'.match(re);
result; 
/* [ "2015-01-02", "2015", "01", "02"
     groups: {year: "2015", month: "01", day: "02"},
    index: 0,
    input: "2015-01-02",
    length: 4 ] */

g flag๋ฅผ ์‚ฌ์šฉํ•œ ๊ฒฝ์šฐ

let re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/g;
const result = '2015-01-02'.match(re);
result;
// ["2015-01-02"]
// length: 1

๋…ผ-์บก์ณ๋ง ๊ทธ๋ฃน(non-capturing group)

?: ๊ธฐํ˜ธ๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด non-capturing ๊ทธ๋ฃน์ด ๋œ๋‹ค.

non-capturing group์€ ๊ฒฐ๊ณผ ๋ฐฐ์—ด์— ์ถ”๊ฐ€๋˜์ง€ ์•Š๋Š”๋‹ค.

let re = /(?:\d{4})-(?:\d{2})-(?:\d{2})/u;
const result = '2015-01-02'.match(re);
result; 
/* ["2015-01-02",
groups: undefined,
index: 0,
input: "2015-01-02",
length: 1] */

(?:x)

x์— ๋งค์น˜๋˜์ง€๋งŒ, ๋งค์น˜๋œ ๋‚ด์šฉ์„ ๊ธฐ์–ตํ•˜์ง€ ๋ชปํ•œ๋‹ค.

์ถ”๊ฐ€ property

groups

key๊ฐ€ ์ด๋ฆ„์ด๊ณ  value๊ฐ€ ์บก์ณ๋ง ๊ทธ๋ฃน์ธ ๋ช…๋ช…๋œ ์บก์ณ๋ง ๊ทธ๋ฃน์˜ object, ์บก์ณ๋ง ๊ทธ๋ฃน์ด ์ •์˜๋˜์–ด ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ undefined

Description

Other methods

  • ์ •๊ทœ์‹์ด ๋ฌธ์ž์—ด๊ณผ ์ผ์น˜ํ•˜๋Š”์ง€ ์•Œ์•„์•ผ ํ•  ๋•Œ๋Š” RegExp ์‚ฌ์šฉํ•œ๋‹ค. RegExp.test()

  • ์ฒซ๋ฒˆ์งธ ์ผ์น˜ ํ•ญ๋ชฉ๋งŒ ์ฐพ์œผ๋ ค๋ฉด RegExp.exec()

  • ์บก์ฒ˜ ๊ทธ๋ฃน์„ ํ™•๋ณดํ•˜๊ณ  ๊ทธ๋กœ๋ฒŒ ํ”Œ๋ž˜๊ทธ๋ฅผ ์„ค์ •ํ•˜๋ ค๋ฉด RegExp.exec() ๋˜๋Š” String.prototype.matchAll() ๋Œ€์‹  ์‚ฌ์šฉํ•œ๋‹ค.

Examples

match() ์‚ฌ์šฉ

match()๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 'Chapter' ๋ผ๋Š” ๋‹จ์–ด์™€ ์— ์ด์–ด์ง€๋Š” 1 ์ด์ƒ์˜ ์ˆซ์ž, ์†Œ์ˆซ์ ์œผ๋กœ ์ˆซ์žํ˜•ํƒœ๊ฐ€ ๋ฐ˜๋ณต๋˜๋Š” ๋ฌธ์ž์—ด์„ ์ฐพ์Œ

i flag๋Š” ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š๋Š”๋‹ค.

const str = 'For more information, see Chapter 3.4.5.1';
const re = /see (chapter \d+(\.\d)*)/i;
const found = str.match(re);

found;
// ["see Chapter 3.4.5.1", "Chapter 3.4.5.1", ".1", index: 22, input: "For more information, see Chapter 3.4.5.1", groups: undefined]

// 'see Chapert 3.4.5.1' ์™„์ „ํžˆ ๋งค์น˜๋œ ๋ถ€๋ถ„
// 'Chapter 3.4.5.1'๋Š” '(chapter \d+(\.\d)*)' ๋ถ€๋ถ„์— ์˜ํ•ด ์บก์ณ๋จ
// .1'์€ '(\.\d)' ๋ถ€๋ถ„์—์„œ ์บก์ณ๋œ ๋งˆ์ง€๋ง‰ ๊ฐ’
// 'index' ์š”์†Œ๊ฐ€ 22๋ผ๋Š”๊ฑด 22๋ฒˆ์งธ ์œ„์น˜๋ถ„ํ„ฐ ์™„์ „ํžˆ ๋งค์น˜๋œ ๋ฌธ์ž์—ด์ด ๋‚˜ํƒ€๋‚จ์„ ์˜๋ฏธํ•œ๋‹ค.
// 'input' ์š”์†Œ๋Š” ์ž…๋ ฅ๋œ ์›๋ž˜ ๋ฌธ์ž์—ด์„ ๋‚˜ํƒ€๋ƒ„

match()์™€ ํ•จ๊ป˜ g (๊ธ€๋กœ๋ฒŒ) ํ”Œ๋ž˜๊ทธ์™€ i(๋Œ€์†Œ๋ฌธ์ž ๋ฌด์‹œ) ํ”Œ๋ž˜๊ทธ ์‚ฌ์šฉํ•˜๊ธฐ

let str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
let regexp = /[A-E]/gi;
let matches_array = str.match(regexp);

matches_array; // ["A", "B", "C", "D", "E", "a", "b", "c", "d", "e"]

๋งค๊ฐœ๋ณ€์ˆ˜ ์—†์ด match() ์‚ฌ์šฉํ•˜๊ธฐ

let str = "๋งค๊ฐœ๋ณ€์ˆ˜ ์—†์ด ์‚ฌ์šฉํ•˜๊ธฐ~";

str.match(); // [""]

๋น„ ์ •๊ทœํ‘œํ˜„์‹ ๊ฐ์ฒด๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์‚ฌ์šฉํ•˜๊ธฐ

๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ๋ฌธ์ž์—ด์ด๋‚˜ ์ˆซ์ž์ด๋ฉด, ํ•ด๋‹น ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ๋‚ด๋ถ€์ ์œผ๋กœ new RegExp(obj) ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ RegExp ๋กœ ๋ณ€ํ™˜๋œ๋‹ค. ๋งŒ์•ฝ ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ํ”Œ๋Ÿฌ์Šค ๊ธฐํ˜ธ์™€ ์ด์–ด์ง€๋Š” ์ˆซ์žํ˜•์ด๋ผ๋ฉด, RegExp() ๋ฉ”์„œ๋“œ๋Š” ํ”Œ๋Ÿฌ์Šค ๊ธฐํ˜ธ๋ฅผ ๋ฌด์‹œํ•œ๋‹ค.

let str1 = 'NaN means not a number. Infinity contains -Infinity and +Infinity in JavaScript',
  str2 = 'My grandfater is 65 years old and My grandmother is 63 years old.',
    str3 = 'The contract was declared null and void.';
str1.match('number'); // 'number' is a string. return ["number"]
str1.match(NaN); // NaN์˜ ํƒ€์ž…์€ number์ด๋‹ค. return ["NaN"]
str1.match(Infinity); // Infinity์˜ ํƒ€์ž…์€ number์ด๋‹ค. return ["Infinity"]
str1.match(+Infinity); // return ["Infinity"]
str1.match(-Infinity); // return ["-Infinity"]
str2.match(65); // return ["65"]
str2.match(+65); // return ["65"]
str3.match(null); // return ["null"]

์ฐธ๊ณ 

Previousstring.repeatNextString.prototype

Last updated 5 years ago

Was this helpful?

์ •๊ทœ์‹์— g flag๊ฐ€ ์—†๋‹ค๋ฉด, ์™€ ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

RegExp.exec()
์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ •๊ทœํ‘œํ˜„์‹์˜ capturing group
MDN web docs - Groups and ranges
RegExp Named Capture Groups