티스토리 뷰

Python

re 기초

techbard 2016.04.29 13:56

# re


import re


patterns = ['term1', 'term2']


text = "This is a string with term1, but not the other term"


if re.search('hello', 'hello world'):

print("Match was found.")

else:

print("No Match was found.")


match = re.search(patterns[0], text)


print(match.start())

print(match.end())


split_term = '@'


phrase = 'What is your email, is it hello@gmail.com?'


print(re.split(split_term, phrase))


print(re.findall('match', 'Here is one match, here is another match'))


# 결과

Match was found.

22

27

['What is your email, is it hello', 'gmail.com?']

['match', 'match']


댓글
댓글쓰기 폼
공지사항
Total
410,043
Today
5
Yesterday
38
«   2019/11   »
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함