Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Regular Expressions in JavaScript Regular Expressions Matching Character Ranges

I can't get match with #2

1 a 2 a 3 a 4 a 5 a 8 a 9 b

I can not match the above I tried [0-9a] as a regex but does not work. What is wrong please?

3 Answers

Rich Zimmerman
Rich Zimmerman
24,062 Points

So right now [0-9a] is only going to match any character that is a number from 0-9 or a, so essentially you're matching each single character as a match. so: [0-9a] matches 0 [0-9a] matches a [0-9a] matches 5 if you're trying to match more than one character, you'll need to define your Regex differently - there's a few ways to do it.

What specifically are you NOT getting a match for?

This worked...

[1-9] [ab]
Christina Giannouli
Christina Giannouli
18,202 Points

I think this works: [0-9] ?[a-z] Note that there is a space between numbers and letters.