How can I get a list like this [30,31,32,33,34,35] when i give "in between 30 and 35" to a python function
Question: As I am not good in regular expression, please help me to get the define the
method. I have a method which takes string as argument and returns a list

    
    
     1. get_values("IN BETWEEN 30 AND 35")  => [30,31,32,33,34,35]
     2. get_values("(in between 35 and 40) and (in [56,57,58])") => [35,36,37,38,39,40,56,57,58]
     3. get_values("(in between 30 and 35) and (IN BETWEEN 40 AND 45)") =>[30,31,32,33,34,35,40,41,42,43,44,45]
    

These and their combinations are the possible cases


Answer: This is a potential solution, but this should really be handled by properly
parsing the SQL syntax using some kind of parser:

    
    
    import re
    def get_values(sql):
        sql = sql.upper()
        between_regex = '(\d+)\s+AND\s+(\d+)'
        ranges = [range(int(a), int(b)) for a, b in re.findall(between_regex, sql)]
    
        in_regex = '\[(.*)]'
        ranges += [[int(y) for y in x.split(',')] for  x in re.findall(in_regex, sql)]
        return [x for r in ranges for x in r]
    
    print get_values("IN BETWEEN 30 AND 35")
    print get_values("(in between 35 and 40) and (in [56,57,58])")
    print get_values("(in between 30 and 35) and (IN BETWEEN 40 AND 45)")
    
    #[30, 31, 32, 33, 34]
    #[35, 36, 37, 38, 39, 56, 57, 58]
    #[30, 31, 32, 33, 34, 40, 41, 42, 43, 44]
    

