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

Java Java Data Structures - Retired Organizing Data Splitting Strings

Expected 11 words but returned 12 with ("[\\s+]"), passed with ("\\s+")

In the splitting strings code challenge, when I used brackets around the regex it returned an extra word. I took the brackets out and the code passed. What is up with that?

1 Answer

Hey Anthony,

if you put something in square brackets in a regex it will try to match each character in the square brackets. The plus inside the square brackets means that the regex will search for a plus sign. It's not using the "+" as a quantifier as it is in "\\s+".

For example, "[a+]" will match "aaaa" four times, while "a+" will match "aaaa" just once.

Kind Regards, Florian

Thank you, that cleared things up for me!

Thanks, Florian! Would have been nice if Craig had explained this before just telling us to use a regex expression that was not even mentioned in the lesson. I kept getting the same issue.