Michael Leikind
Michael Leikind

Reputation: 11

Regular Expression for numbers and letters but not only numbers

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

Answers (3)

daramarak
daramarak

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

Avinash Raj
Avinash Raj

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]+:

DEMO

>>> 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

mkorpela
mkorpela

Reputation: 4395

Something like this

 /([A-Z]*[0-9]*[A-Z]+)+/

Upvotes: 0

Related Questions