Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

i didn't realize that it was possible to name a capturing group. this is an awesome example.


ruby > 1.9


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'}




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: