fork download
  1.  
  2. import re
  3.  
  4. pattern = r"\bSOURCE#.*\s*^\[1](.*\s*^(?!\[\d+]).*\bPN[QR](?:\n(?!\[\d+]).*)*(?:\n\[\d+].*)*)"
  5.  
  6. s = ("**** SOURCE#24 ****\n\n"
  7. "[1] Source Location [Local/Remote] : Remote\n\n"
  8. " Remote Host Name : PNQ\n"
  9. " User Name : foo\n\n"
  10. "[2] Source directory : HDPGWRF\n"
  11. "[3] Directory poll interval : 30\n"
  12. "[4] File name format : ACR_FILEFORMAT\n"
  13. "[5] Delete files from source : y\n\n"
  14. "**** SOURCE#25 ****\n\n"
  15. "[1] Source Location [Local/Remote] : Remote\n\n"
  16. " Remote Host Name : PNR\n"
  17. " User Name : foo\n\n"
  18. "[2] Source directory : HDPGWRF\n"
  19. "[3] Directory poll interval : 30\n"
  20. "[4] File name format : ACR_FILEFORMAT\n"
  21. "[5] Delete files from source : y\n\n"
  22. "**** SOURCE#26 ****\n"
  23. "etc.....")
  24.  
  25. print(re.findall(pattern, s, re.MULTILINE))
Success #stdin #stdout 0.02s 9756KB
stdin
Standard input is empty
stdout
['  Source Location [Local/Remote]          : Remote\n\n Remote Host Name : PNQ\n User Name        : foo\n\n[2]  Source directory                        : HDPGWRF\n[3]  Directory poll interval                 : 30\n[4]  File name format                        : ACR_FILEFORMAT\n[5]  Delete files from source                : y', '  Source Location [Local/Remote]          : Remote\n\n Remote Host Name : PNR\n User Name        : foo\n\n[2]  Source directory                        : HDPGWRF\n[3]  Directory poll interval                 : 30\n[4]  File name format                        : ACR_FILEFORMAT\n[5]  Delete files from source                : y']