-1

I was looking for the answer in stackoverflow but I couldn't find a case like the mine. For me is really difficult regex expressions.

I have one string like this (without quotation marks (")): 1) "09:10,10:00" 2) "11:40,12:35"

And for each one, I need to fill four variables with numeric the parts (without quotation marks (")) 1) variable1_hourFrom="09" variable2_hourTo="10" variable3_minuteFrom="10" variable4_minuteto="00"

2) variable1_hourFrom="11" variable2_hourTo="12" variable3_minuteFrom="40" variable4_minuteto="35"

I'm using regex expressions function from BigQuery REGEXP_EXTRACT(variable, r'regex_expresion')

Thanks for the help and regards!

1 Answers1

-1

Use parentheses to group matches. The match .groups() method will return the items matched. Answer demo in Python:

import re

items = "09:10,10:00","11:40,12:35"

for item in items:
    m = re.match(r'(\d\d):(\d\d),(\d\d):(\d\d)',item)
    hourFrom,minuteFrom,hourTo,minuteTo = m.groups()
    print(hourFrom,minuteFrom,hourTo,minuteTo)
09 10 10 00
11 40 12 35
Mark Tolonen
  • 132,868
  • 21
  • 152
  • 208