# http://stackoverflow.com/q/33587745/5290909
# Match Python IF STATEMENTS
import re
 
if_statement = re.compile(r'''
	#if statement (group 1 captures the indentation)
	^([ \t]*)  if\b  .*  $
	
	#code
	(?:
	    #comments with any indentation
	    (?:
	        \s*?
	        \n  [ \t]*  [#].* 
	    )*
	
	    #Optional elif/else lines
	    (?:
	        \s*?
	        \n\1  el(?:se|if)\b  .*  $
	    )?
	
	    #following lines with more indentation
	    \s*?
	    \n\1  [ \t]  .*
	)*
	
	\n? #last newline char
''', re.MULTILINE | re.VERBOSE)


test_str = r'''
	    weight = float(input("How many pounds does your suitcase weigh? "))
	    if weight > 50:
	        print("There is a $25 charge for luggage that heavy.")
	    print("Thank you for your business.")
	
	    if totalHours <= 40:
	        regularHours = totalHours
	        overtime = 0
	    else:
	        overtime = totalHours - 40
	        regularHours = 40
	    return hourlyWage*regularHours + (1.5*hourlyWage)*overtime
	
	    if score >= 90:
	        letter = 'A'
	    else:   # grade must be B, C, D or F
	        if score >= 80:
	            letter = 'B'
	        else:  # grade must be C, D or F
	            if score >= 70:
	                letter = 'C'
	            else:    # grade must D or F
	                if score >= 60:
	                    letter = 'D'
	                else:
	                    letter = 'F'
	    return letter
	
	def letterGrade(score):
	    if score >= 90:
	        letter = 'A'
	    elif score >= 80:
	        letter = 'B'
	    elif score >= 70:
	        letter = 'C'
	    elif score >= 60:
	        letter = 'D'
	    else:
	        letter = 'F'
	    return letter
	
	def printAllPositive(numberList):
	    for num in numberList:
	        if num > 0:
	            print(num)
	
	printAllPositive([3, -5, 2, -1, 0, 7])
	
	    for i in range(600):
	        shape.move(dx, dy)
	        center = shape.getCenter()
	        x = center.getX()
	        y = center.getY()
	        if x < xLow:
	            dx = -dx
	        elif x > xHigh:
	            dx = -dx
	        if y < yLow:
	            dy = -dy
	        elif y > yHigh:
	            dy = -dy            
	        time.sleep(delay)
'''
 
 
# Loop matches
m = 0
for match in if_statement.finditer(test_str):
	m += 1
	print( 'Match #%s\t[%s:%s]:\n%s' %(m, match.start(), match.end(), match.group()))
	
if m == 0:
	print("NO MATCH")