Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Bad character range in regex

Look at my answer

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Yep, that's one of the shortcomings of a fairly naive engine like regex uses. But it's also really easy to avoid; just keep literal hyphens on the ends of your sets. Hyphens that are outside of sets, like r'a-z', will be caught just as they are.

Suppose if you put - operator in the middle of the regex, you are likely to get that error look at this [-\w\d] or [\w\d-] would be the correct form! [a-z] is used to match from a-z, this - would represent the range. so, If you put - in the middle of the expression, it will treat it a range, some times they will be incompatible types which would result in error! comments,suggestions are welcome!