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 Finding Repeated Characters

In the last example, inconsistent result \w* vs \w+

In the last example, using the following test case

E4763GHC
7896TOB3P
L0003

in the regexpal.com site, when I try \w*, I only get the first row highlight. But when I use \w+ I get all rows highlighted. Why is this?

1 Answer

Steven Parker
Steven Parker
231,210 Points

The wildcard (*) isn't very useful with one token, since it matches zero or more of that token. So it will generally be used in combination with other tokens. For example: \w\w* will do the same thing as \w+.

Also, be sure that the regexpal "global" flag is set the same way when comparing expressions. My guess is that you had it off for the first expression but on for the second.