s = 'onesixx'
pattern = re.compile('sixx')
result = pattern.match(s)
result = re.match(pattern, s) # same above
# -----------------
re.match('x', s)
# None
re.fullmatch('onesixx', s)
#
re.search('x', s)
#
re.findall('x', s)
# ['x', 'x']
re.finditer('x', s)
#
for mobj in re.finditer('x', s):
print(mobj)
#
#
# -------Match Object의 메소드 ----------
for mobj in re.finditer('x', s):
print(f'group: {mobj.group()}')
print(f'start: {mobj.start()}')
print(f'end: {mobj.end()}')
print(f'span: {mobj.span()}')
# group: x
# start: 5
# end: 6
# span: (5, 6)
# group: x
# start: 6
# end: 7
# span: (6, 7)
exList = ['iiiabcuuu', 'abcooo', 'abcppp', '123ttt', '123yyy']
[s for s in exList if "abc" in s]
# ['iiiabcuuu', 'abcooo', 'abcppp']
[s for s in exList if re.match("abc", s)]
# ['abcooo', 'abcppp']
slice와 islice는 모두 Python에서 제공하는 slicing 기능을 사용하는 함수입니다. 두 함수의 주요 차이점은 slice는 일반적인 시퀀스에 사용되며, islice는 iterator에 사용된다는 점입니다. 위의 예제에서 slice는 리스트의 일부를 새로운 리스트로 반환하고, islice는 iterator의 일부를 새로운 iterator로 반환합니다.