Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # text i wanna match:
- keyone=valueone abc requestClientApplication=Mozilla/5.0 (compatible; heritrix/3.3.0-SNAPSHOT-20150302-2206 +http://127.0.0.1) keytwo=value two abc
- # regex used:
- requestClientApplication=((?:.(?![a-zA-Z\d]+=))*)
- # works on https://regex101.com/#python
- # Getting exact full match ("Mozilla/5.0 (compatible; heritrix/3.3.0-SNAPSHOT-20150302-2206 +http://127.0.0.1)" in this case)
- # but in python:
- for file in os.listdir(os.getcwd()):
- if file.endswith(".log"):
- with open(file) as f:
- for line in f: # line is the example text above
- matchclapp = re.search('requestClientApplication=((?:.(?![a-zA-Z\d]+=))*)', line)
- print(matchclapp)
- # Getting this output:
- # <_sre.SRE_Match object; span=(136, 273), match='requestClientApplication=Mozilla/5.0 (compatible;>
- # Match was cut in the middle...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement