강의

멘토링

로드맵

Inflearn Community Q&A

hesher20162354's profile image
hesher20162354

asked

Want to learn JavaScript properly?

Regular Expression (RegExp)

정규식 관련해서 질문이 있습니다.

Written on

·

302

1

const str ='to lose your path is the way ro find that path'

const patt=/([a-f])\w+/i;
console.log(str.match(patt));-
 
다음과 같은 예제에서 괄호는 어떤 역할을 하는 건가요.
괄호가 있고 없고에 따라 결과가
 
괄호 없을 때
[ 'ath', input: 'to lose your path is the way ro find that path', groups: undefined ]
 
괄호 있을 때
[ 'ath', 'a', input: 'to lose your path is the way ro find that path', groups: undefined ]
이와 같이 나옵니다.
javascriptHTML/CSSes6

Quiz

객체의 메서드 안에서 `this` 키워드는 주로 무엇을 가리킬까요?

전역 객체 (예: window)

메서드가 포함된 객체 자체

메서드를 호출한 함수

HTML 문서

Answer 2

1

realprogrammers님의 프로필 이미지
realprogrammers
Instructor

정규식에서 괄호를 사용하는 것을 포획 괄호(Capturing Parentheses)라고 합니다. 매칭되는 것을 일단 기억을 하게 됩니다. 그래서 괄호가 있을 때는 ([a-f])와 일치되는 문자를 일단 기억하고, 그 다음 [a-f]\w+ 를 찾게 됩니다. 

그래서 match 함수로 출력을 하면 a와 ath 가 나오게 됩니다.

0

hesher20162354님의 프로필 이미지
hesher20162354
Questioner

 

정규표현식의 괄호가 그룹화해주는 저장하는 있어서

표현식에 일치하는 문자들중 괄호의 표현식에 해당하는 문자가 매치함수를 통해 나온건가요?

hesher20162354's profile image
hesher20162354

asked

Ask a question