Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. # text i wanna match:
  2.  
  3. keyone=valueone abc requestClientApplication=Mozilla/5.0 (compatible; heritrix/3.3.0-SNAPSHOT-20150302-2206 +http://127.0.0.1) keytwo=value two abc
  4.  
  5. # regex used:
  6.  
  7. requestClientApplication=((?:.(?![a-zA-Z\d]+=))*)
  8.  
  9. # works on https://regex101.com/#python
  10. # Getting exact full match ("Mozilla/5.0 (compatible; heritrix/3.3.0-SNAPSHOT-20150302-2206 +http://127.0.0.1)" in this case)
  11. # but in python:
  12.  
  13. for file in os.listdir(os.getcwd()):
  14. if file.endswith(".log"):
  15. with open(file) as f:
  16. for line in f: # line is the example text above
  17. matchclapp = re.search('requestClientApplication=((?:.(?![a-zA-Z\d]+=))*)', line)
  18. print(matchclapp)
  19.  
  20. # Getting this output:
  21.  
  22. # <_sre.SRE_Match object; span=(136, 273), match='requestClientApplication=Mozilla/5.0 (compatible;>
  23. # Match was cut in the middle...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement