This is my input text: "you have a choice between 1, 2 or 3 bedrooms"
I want to get the number of bedrooms, so one or more numbers before "bedroom" (allowing: ',', '-', 'and', '&', 'or', and 'whitespace' between numbers)
I have tried this pattern: (1|2|3|4|5|6|,|-|\s|&|and|or){1,12}bedroom on regex101 and it works fine.
But my Python code below, does not work:
text = "you have a choice between 1, 2 or 3 bedrooms"
number_range_pattern = r"(1|2|3|4|5|6|,|-|\s|&|and|or){1,12}"
bedrooms = re.search(number_range_pattern + r"bedroom", text)
if bedrooms and len(bedrooms.groups()) >= 1:
match = bedrooms.group(1) # <-- match is a whitespace
Result: match is whitespce
I want the result to be: "1, 2 or 3"