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

Julio Akiyama
Julio Akiyama
9,068 Points

Is it correct?

[0-9]{4} [A-Za-z]{5}
8345 Gable
7238 Gable
2349 Table
8475 Cable
0994 Fable
1047 Zable
[0-9]{4}[0-9]?
4849
4472
4901
40502
43470
40496

It worked, but is it the correct way to do so? Thank you!

1 Answer

I would chane "[0-9]{4}[0-9]?" to "\d{4,5}" and "[0-9]{4} [A-Za-z]{5}" would become "\d{4} [A-Za-z]{5}". Good luck!

Keep in mind: [0-9] is not always equivalent to \d. In python3, [0-9] matches only 0123456789 characters, while \d matches [0-9] and other digit characters, for example Eastern Arabic numerals ٠١٢٣٤٥٦٧٨٩.