정규 표현식 re 모듈

·2023년 6월 3일
import re
pattern = re.compile('정규표현식')
match = pattern.match("문자열")

컴파일된 패턴 객체의 메소드

  • match() : 문자열 처음부터 정규식과 매치 조사
  • search() : 문자열 전체 검색하여 정규식과 매치 조사
  • findall() : 정규식과 매치되는 substring을 리스트로 반환
  • finditer() : 정규식과 매치되는 substring을 iterable 객체로 반환
import re

def solution(babbling):
    cnt = 0
    pattern = re.compile('^(aya|ye|woo|ma)+$')
    for word in babbling:
        if pattern.match(word):
            cnt += 1
    return cnt
^ 시작
$ 끝
| or
+ 하나 이상 반복

https://wikidocs.net/4308#_5

profile
개발 여정기

0개의 댓글