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

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?

4 Answers

Rich Zimmerman
Rich Zimmerman
24,063 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.