-
-
Save avit/c5d28db4feedf01bc041 to your computer and use it in GitHub Desktop.
Regexp: repeating capture group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pattern = %r{ | |
\A | |
\s*(?:Every)?\s* | |
(?: | |
(?<monthweek>1st|2nd|3rd|4th|last|first|second|third|fourth) | |
(?: | |
\s*(?:and|&|,)\s* | |
(?<monthweek>1st|2nd|3rd|4th|last|first|second|third|fourth) | |
){0,3} | |
)?\s* | |
(?<weekday>(?:Sun|Mon|Tues|Wednes|Thurs|Fri|Satur)day)s?\s* | |
(?:of each month|of the month|every month)?\s* | |
\z | |
}xi | |
pattern.match "first and second and third monday" | |
# #<MatchData | |
# "first and second and third monday" | |
# monthweek:"first" | |
# monthweek:"third" | |
# weekday:"monday"> | |
# What happened to monthweek: "second"? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment