daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import re
  2.  
  3. s = "A 1 (B 2 C 3 D 4) E 5"
  4.  
  5. re.findall("(w+sd+)", s)                   # ['A 1', 'B 2', 'C 3', 'D 4', 'E 5']
  6. re.findall("(?<=()(w+sd+)", s)            # ['B 2']
  7. re.findall("(w+sd+)(?=))", s)             # ['D 4']
  8. re.findall("(?<=()(w+sd+)(?=))", s)      # []
  9.  
  10. # desired result: ["B 2", "C 3", "D 4"]
  11.    
  12. import re
  13.  
  14. s = "A 1 (B 2 C 3 D 4) E 5"
  15. m = re.search(r"((?P<content>.*?))", s)
  16. if m:
  17.     val = m.group("content")
  18.     print(re.findall(r"ws+d", val))
  19.    
  20. ['B 2', 'C 3', 'D 4']
  21.    
  22. s = "A 1 (B 2 C 3 D 4) E 5 (X 2 Y 3 Z 4) V 4"
  23. for m in  re.findall(r"(.*?)", s):
  24.     print(re.findall(r"ws+d", m))
  25.    
  26. ['B 2', 'C 3', 'D 4']
  27. ['X 2', 'Y 3', 'Z 4']
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top