Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- t_str = "44hogehoge[23][34][1,2,45][6,][]"
- ptnA = re.compile(r'[{1}([0-9]{1,2},?s*)+]{1}', flags=re.MULTILINE)
- print(re.findall(ptnA,t_str))
- print(re.search(ptnA,t_str).group())
- >>>['23', '34', '45', '6,']
- >>>[23]
- t_str = "44hogehoge[23][34][1,2,45][6,][]"
- ptnB = re.compile(r'[([0-9]{0,2},?s*)?]', flags=re.MULTILINE)
- ptnC = re.compile(r'[[0-9]{0,2}', flags=re.MULTILINE)
- print(re.findall(ptnB,t_str))
- print(re.findall(ptnC,t_str))
- print(re.search(ptnB,t_str).group())
- print(re.search(ptnC,t_str).group())
- >>>['23', '34', '6,', '']
- >>>['[23', '[34', '[1', '[6', '[']
- >>>[23]
- >>>[23
- # n, の組が3連続の場合のみ合致
- ptnA2 = re.compile(r'[{1}([0-9]{1,2},?s*){3}]{1}', flags=re.MULTILINE)
- print(re.findall(ptnA2,t_str))
- print(re.search(ptnA2,t_str).group())
- >>>['45']
- >>>[1,2,45]
Add Comment
Please, Sign In to add comment