0

I'm new to Regular Expressions. I'm trying to identify the year in

vsdir

as an integer e.g. number (2013) where

vsdir="vs2013"

so that I can apply an if statement where if this number is < 2010 (one outcome), else (another outcome)

I'm doing this in a pythpon script. Can anyone give any suggestions please?

1 Answers1

0

I think you mean this,

if int(vsdir[-4:]) < 2010:
    print("yeh, less tha 2010")
else:
    print("greater than 2010")

OR

if int(re.search(r'\d+',vsdir).group()) < 2010:
    print("yeh, less tha 2010")
else:
    print("greater than 2010")
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274