Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identify a string pattern

Status
Not open for further replies.

ddrillich

Technical User
Jun 11, 2003
546
0
0
US
Good Day,

I would like to identify whether a string has the following format: 'any char sequence.... SF Jun 23 2006'.
It's a sequence of characters followed by SF and then a date in this specific format.

Any ideas?

Thanks,
Dan
 
from time import strptime
str = 'jdhgjkdfhgjsdhgklhsdljSF Jun 23 2006'
try:
MyDate = strptime(str[-11:], '%b %d %Y')
ValidDate = 1
except:
ValidDate = 0

if str[-14:-12]=='SF' and ValidDate:
print 'string is of correct format'
else:
print 'string is NOT correct'

Hope this works for you.
Peter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top