정규식 연산 re

Published by onesixx on

https://onesixx.com/regex/

https://docs.python.org/ko/3/library/re.html#module-re

https://www.nextree.co.kr/p4327/

정규표현식 관련 Utility Site

정규표현식 Test 및 생성 Util http://gskinner.com/RegExr/
정규표현식 도식화 표현Util http://www.regexper.com/

import re
regex = re.compile("정규표현식")   # 패턴객체 만들기
match = regex.match('검사할문장')  # 검사할 문자과 패턴이 일치하는지 
result = match.group()          # 검사할문장에서 패턴매치된 문자열 리턴
print(result)

패턴만들때 컴파일 옵션

  • re.dotall re.S
  • re.I 대소문자 Ignore Case
  • re.M 각줄마다 ^
  • re.V 정규식 줄바꿈 허용

패턴적용시, 매소드

  • match
  • search
  • findall 일치단어리스트
  • finditer 매치객체

Match객체의 매소드

  • group() 해당문자열 리터
  • start()
  • end()
  • span() 시작 끝.
Categories: Python Basic

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x