From: donn@...
Date: 2006-11-16T02:21:59+09:00
Subject: Group names in regular expressions
Given the following regex to parse telephone numbers:
/^(\(?(?[0-9]{3})\)?)?(\-| )?(?[0-9]{3})(\-|
)?(?[0-9]{4})/
Is there a regex.method to access the parse data by group name? I was
hoping something like the following behavior:
rx = /^(\(?(?[0-9]{3})\)?)?(\-| )?(?[0-9]{3})(\-|
)?(?[0-9]{4})/
md = rx.match('800 325-3535')
puts md['area']+md['exch']+md['party']
I'm not that skilled with regex (yet), so I don't know if I could
extend the regex class with my own method. I'm not sure what all data
is available to me after parsing.
dvn