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

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Matching Character Ranges with Regex

8345 Gable 7238 Gable 2349 Table 8475 Cable 0994 Fable 1047 Zable

I'm able to match the above Strings with the following pattern - [0-9][0-9][0-9][0-9] ?[A-Z][a-z][a-z][a-z][a-z]

But isn't there a better way than this, or have I got it right? It seems a bit overkill :)

2 Answers

Christopher Augg
Christopher Augg
21,223 Points

Heya,

have your tried [0-9]{4} ?[A-Z][a-z]{4}

This may help: REX EGG

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Thanks! We haven't seen that syntax yet in this video. That's a better way of doing it, I think. I'll link it later if I spot it! :)

huckleberry
huckleberry
14,636 Points

With what is taught and what we've learned up until the point of this video (which is what folks should be answering with imho ;) ) it seems to me it would be

[0-9][0-9][0-9][0-9] [A-Z]able

I'm taking the approach of least code possible to accomplish a full match of all given strings in the provided text thus no range notation for text that is identical as is the case with 'able'.

Just my double pennies is all.

Cheers,

Huck - :sunglasses: