■ 그룹핑 문자열 명칭 설정하기

----------------------------------------------------------------------------------------------------

구분

코드

 

#1

 

import re

 

srePattern = re.compile(r'(?P<name>\w+)\s+(\d+[-]\d+[-]\d+)')

sreMatch = srePattern.search('park 111-2222-3333')

print(sreMatch.group('name'))

 

[결과]

 

'park'

 

 

#2

 

import re

 

srePattern = re.compile(r'(?P<word>\b\w+)\s+(?P=word)')

sreMatch = srePattern.search('Paris in the the spring')

print(sreMatch.group())

 

[결과]

 

'the the'

 

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG