[RegExp]_정규표현식

이건모·2019년 6월 7일
0

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/RegExp#%EB%A7%A4%EA%B0%9C%EB%B3%80%EC%88%98

function vowelsCounter(text) {
    // Search text with Regex and store all matching instances 
    let matchingInstances = text.match(/[aeiou]/gi);

    // Check if matching instances exist then calculate length
    if (matchingInstances) {    
        // Return number of vowels
        return matchingInstances.length
    } else {
        return 0
    }
}

-> 정규표현식을 사용하여 모음의 갯수를 찾아내는 함수

profile
I'm a WebDev!

0개의 댓글