Reputation: 11
I have this string :
S3UPLOAD:Uploading file: /var/mobile/Applications/999445D0-5B4D-4078-9B81-4F65D3474971/Documents/2014-08-25 Driving 22.58.39/2014-08-25 Driving 22.58.39.vmd.zip 783:00
I would like find a regex that will match only substrings like S3UPLOAD:
but not 783:
.
Substrings may contain either capital letters and numbers or capital letters only, not the number(s) only.
Tried this this exp.
/[A-Z][A-Z0-9]+:/
but its not efficient, as it will also match 783:
substring.
Upvotes: 0
Views: 1489
Reputation: 6155
Covers capital letters only, and mixed with numbers. But must contain a capital.
[A-Z0-9]*[A-Z][A-Z0-9]*:
Upvotes: 1
Reputation: 174844
You could try the below regex to match the substrings which contain either capital letters and numbers or capital letters only, not the number(s) only.
[A-Z0-9]*[A-Z][0-9][A-Z0-9]*:|[A-Z]+:
>>> import re
>>> s = "S3UPLOAD:Uploading file: /var/mobile/Applications/999445D0-5B4D-4078-9B81-4F65D3474971/Documents/2014-08-25 Driving 22.58.39/2014-08-25 Driving 22.58.39.vmd.zip 783:00"
>>> m = re.search(r'[A-Z0-9]*[A-Z][0-9][A-Z0-9]*:|[A-Z]+:', s).group()
>>> m
'S3UPLOAD:'
Upvotes: 1