[Leetcode] 10. Regular Expression Matching

Seongjun Lee·2022년 2월 19일
0

[Leetcode] - Problem

목록 보기
10/43
post-thumbnail

Problem

문제 링크

정규 표현식의 Matching 함수를 구현하는 문제

Solution

문제는 정규식을 사용하는 방법을 물어보고있다. 주어진 문자열이 정확하게 패턴의 값과 같은지를 물어보고 있기때문에 정규식패턴에 ^,$ 을 넣어서 처음과 끝까지 비교할 수 있도록 하였다.

JS Code

/**
 * @param {string} s
 * @param {string} p
 * @return {boolean}
 */
var isMatch = function(s, p) {
    return RegExp('^'+p+'$').test(s)
};
profile
Hi there 👋

0개의 댓글