JS10 Day 7: Regular Expressions III

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:52 판 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

개요[ | ]

JS10 Day 7: Regular Expressions III
해커랭크 10 Days of Javascript
# 문제 비고
6-7 Day e
18 JS10 Day 6: Bitwise Operators
19 JS10 Day 6: JavaScript Dates
20 JS10 Day 7: Regular Expressions I
21 JS10 Day 7: Regular Expressions II
22 JS10 Day 7: Regular Expressions III

상단
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    
    main();    
});

function readLine() {
    return inputString[currentLine++];
}
구현예시 1
function regexVar() {
    /*
     * Declare a RegExp object variable named 're'
     * It must match ALL occurrences of numbers in a string.
     */
    let re = /[0-9]+/g;
    /*
     * Do not remove the return statement
     */
    return re;
}
구현예시 2
function regexVar() {
    /*
     * Declare a RegExp object variable named 're'
     * It must match ALL occurrences of numbers in a string.
     */
    let re = /\d+/g;
    /*
     * Do not remove the return statement
     */
    return re;
}
하단
function main() {
    const re = regexVar();
    const s = readLine();
    
    const r = s.match(re);
    
    for (const e of r) {
        console.log(e);
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}