From: Kyle Schmitt Date: 2008-05-14T00:59:20+09:00 Subject: detail on a regex? Is there a way to pull details out of a regular expression's failure? I'm running into a situation where I've got some validation methods, and I'm resorting to passing in both a regular expression and a range. I know quite well I could just use a range inside of a regex, and would rather, but I need to get the range in order to have some useful error messages. For example, the string must be 3 to 8 characters long, start with a letter, and may contain letters numbers or dashes. I would like to just use this: some_string=~/^[a-z][-a-z0-9]{2,7}$/i But if the match fails, I can't give out any good error messages without further inspecting the string, so I end up with some_string=~/^[a-z][-a-z0-9]$/i [3..8].include?some_string.length Just so I can give reasonable error messages. --Kyle