정규식(3)
-
정규식
import re # abcd, book, desk # ca?e # care, cafe, case, cave #case, ca~~ 너무 힘든 과정 p=re.compile('ca.e') #. (ca.e): 하나의 문자를 의미 # care, cafe | caffe x #^(^de) : 문자열의 시작 -> desk , destination | fade x # $ (se$) : 문자열의 끝 > case, base , |fcae x def print_match(m): if m: print('m.group():',m.group()) #일치하는 문자열 반환 print('m.string():',m.string) #입력받은 문자열 print('m.start():', m.start()) #일치하는 문자열의 시작 index..
2024.03.11 -
정규 표현식 정리 [• . ^ $ * + ? { } [ ] \ | ( ) ]
expression = ^b...s$ : 'b'로 시작하고 's'로 끝나는 다섯 글자 문자열과 일치 함 match or no match? basvs : match babcds : no match (글자 수 오류) bsssa : no match (끝나는 문자 오류 -> ^b...a$의 표현은 match 가능 Blaws : no match (대소문자 구분 오류) bn ans : no match (공백도 카운팅) [정규식 syntax] 메타 문자 : RegEx 엔진에 의해 특별한 방식으로 해석되는 문자 • . ^ $ * + ? { } [ ] \ | ( ) 대괄호 : [] 일치시키려는 문자 집합을 지정 expression : [qwer] match or no match? q : 1match qw : 2match..
2023.11.30 -
정규표현식 re 모듈
#re 와 replace를 활용해 특정 문자열 빼고 추출하기 import re # Your input string input_string = "Some 한국어 characters here" # Remove Korean characters #output_string = re.sub('[가-힣]', '', input_string) output=input_string.replace('[가-힣]','') print(output_string) "Some 한국어 characters here" 문자열이 존재한다. 영어 문자 사이에 '한국어'라는 한글이 껴있는데 삭제하는 방법이 없을까? 해결을 위해 re모듈을 사용한다. re.sub() : 정규 표현식의 sub메소드는 정규식을 이용해 문자열을 치환하는 방법 re.sub..
2023.11.25