Answer the question
In order to leave comments, you need to log in
How to extract the desired data from a string with a regular expression?
I have a line like "9:00 every 5 days"
I need to pull out separately:
1) time time = "9:00"
2) number of days days = "5"
I need two regular expressions, three hours of Google did not help.
Answer the question
In order to leave comments, you need to log in
str = '9:00 every 5 days'
/(\d+)\sdays?\z/.match(str)[1] # => "5"
/([^\s]+)\s/.match(str)[1] # => "9:00"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question