본문 바로가기

Regular Expression4

[ 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 ] 정규표현식[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.
[ python ] 정규표현식[1] Mastering Python Regular Expressions http://www.packtpub.com/ Authors : Félix López 제1장 Introducing Regular Expressions 정규식은 텍스트 문자열이 가져야 하는 형식을 정의하는 텍스트 패턴입니다. 이를 사용하여 다음 활동을 수행할 수 있습니다. • Check - 입력이 주어진 패턴을 따르는지 확인합니다. 예를 들어, 입력한 값이 HTML formulary에 맞는 유효한 이메일 주소인지 확인 • Search - 텍스트에서 패턴 모양을 찾습니다. 예를 들어 한 번의 스캔으로 문서에 "color" 또는 "colour"이라는 단어가 나타나는지 확인 • Extract - 텍스트의 특정 부분을 추출합니다. 예를 들어 주소의 .. 2022. 10. 27.