전체 글30 [ Python ] 정규표현식 Table 및 우선순위 Special characters \ escape special characters . matches any character ^ matches beginning of string $ matches end of string [5b-d] matches any chars '5', 'b', 'c' or 'd' [^a-c6] matches any char except 'a', 'b', 'c' or '6' R|S matches either regex R or regex S () creates a capture group and indicates precedence Quantifiers * 0 or more (append ? for non-greedy) + 1 or more (append ? for non-gree.. 2022. 11. 1. [ python ] 정규표현식[5] Mastering Python Regular Expressions http://www.packtpub.com/ Authors : Félix López 제5장 Performance of Regular Expressions Benchmarking regular expressions with Python import re from time import time as now import cProfile # 함수 처리 과정 및 속도 측정 # 실행 속도 촉정 (ms) def test(f, *args, **kargs): start = now() f(*args, **kargs) print("The function %s lasted: %.12fms" % (f.__name__, (now() - start)*10**3)) .. 2022. 10. 31. [ python ] 정규표현식[4] Mastering Python Regular Expressions http://www.packtpub.com/ Authors : Félix López 제4장 Look Around 더 강력한 종류의 zero-width assertion(캐릭터 소비와 매칭없이 input의 포지션이 알맞는지를 보증). 캐릭터 소비없이, 매칭의 positive or negative result를 반환. Look ahead Positive look ahead import re expr1 = r'fox' expr2 = r'(?=fox)' data = "The quick brown fox jumps over the lazy dog" pattern = re.compile(expr1) result = pattern.search(data.. 2022. 10. 30. [ Python ] 정규표현식[3] Mastering Python Regular Expressions http://www.packtpub.com/ Authors : Félix López 제3장 Grouping : ( ) 그룹화는 다음과 같은 작업을 수행할 수 있는 강력한 도구입니다. quantifier를 적용하기 위한 subexpression생성 예) 단일 문자가 아닌 subexpression을 반복합니다. alternation 범위를 제한 전체 표현식을 변경하는 대신 대체해야 할 항목을 정확히 정의할 수 있습니다. 일치된 패턴에서 정보 추출 예) 주문 목록에서 날짜를 추출합니다. 추출된 정보를 정규식에서 재사용(가장 유용한 기능) 예) 반복되는 단어를 감지하는 것입니다. Introduction subexpression 생성 괄호는 정규식.. 2022. 10. 27. 이전 1 ··· 4 5 6 7 8 다음