Guest User

Untitled

a guest
Jun 25th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. t_str = "44hogehoge[23][34][1,2,45][6,][]"
  2. ptnA = re.compile(r'[{1}([0-9]{1,2},?s*)+]{1}', flags=re.MULTILINE)
  3. print(re.findall(ptnA,t_str))
  4. print(re.search(ptnA,t_str).group())
  5.  
  6. >>>['23', '34', '45', '6,']
  7. >>>[23]
  8.  
  9. t_str = "44hogehoge[23][34][1,2,45][6,][]"
  10. ptnB = re.compile(r'[([0-9]{0,2},?s*)?]', flags=re.MULTILINE)
  11. ptnC = re.compile(r'[[0-9]{0,2}', flags=re.MULTILINE)
  12. print(re.findall(ptnB,t_str))
  13. print(re.findall(ptnC,t_str))
  14. print(re.search(ptnB,t_str).group())
  15. print(re.search(ptnC,t_str).group())
  16.  
  17. >>>['23', '34', '6,', '']
  18. >>>['[23', '[34', '[1', '[6', '[']
  19. >>>[23]
  20. >>>[23
  21.  
  22. # n, の組が3連続の場合のみ合致
  23. ptnA2 = re.compile(r'[{1}([0-9]{1,2},?s*){3}]{1}', flags=re.MULTILINE)
  24. print(re.findall(ptnA2,t_str))
  25. print(re.search(ptnA2,t_str).group())
  26.  
  27. >>>['45']
  28. >>>[1,2,45]
Add Comment
Please, Sign In to add comment