Re:Rubular - a Ruby regular expression editor
by logical42 on Tuesday October 23, 2012 @03:12PM
(#4689826)
i didn't realize that it was possible to name a capturing group. this is an awesome example.
[ Parent
| on HN ]
Re:Rubular - a Ruby regular expression editor
by aaronblohowiak on Tuesday October 23, 2012 @03:21PM
(#4689885)
ruby > 1.9
Re:Rubular - a Ruby regular expression editor
by pjscott on Tuesday October 23, 2012 @09:12PM
(#4691181)
Also available in Python's re module, with a syntax that's just different enough to be irritatingly incompatible.
>>> import re
>>> r = re.compile(r'(?P<month>\d{1,2})\/(?P<day>\d{1,2})\/(?P<year>\d{4})')
>>> r.search("Today's date is: 10/23/2012.").groupdict()
{'month': '10', 'day': '23', 'year': '2012'}