Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Regular Expressions in JavaScript Regular Expressions Excluding Characters

Victor Stanciu
seal-mask
.a{fill-rule:evenodd;}techdegree
Victor Stanciu
Full Stack JavaScript Techdegree Student 11,184 Points

My solution for this practice

Here is my solution:

  1. Exclude "a" and whitespace, and match one or more alphanumeric characters: [^a\s]\w+
  2. Match 5 numbers: \d{5}
  3. Match commas: ,
  4. Exclude "<", ">", "/" and whitespace and match one or more alphanumeric characters: [^<>\/\s]\w+

I hope this helps!

Victor Stanciu
seal-mask
.a{fill-rule:evenodd;}techdegree
Victor Stanciu
Full Stack JavaScript Techdegree Student 11,184 Points

Hi Jason Larson!

Thank you for sharing your opinion!

For the first example, I think they meant us to exclude the exact "aaaaa" string, given that we are working with string made of only letters.

For 2 and 3 I went for the "easy way", because in the Teacher's Notes it states "Using what you've learned so far, create a regular expression..." so I used everything I learned in the course up to that point in time.

For number 4 you might be correct. We must exclude "/" because it says "Match only text characters...". I will edit the original post to avoid confusion for future readers.

1 Answer

Jason Larson
Jason Larson
7,955 Points

The examples are pretty vague, but the first one is not clear if you should not match the letter 'a' or not match something that has consecutive letters. I honestly couldn't figure out how to do it generically for multiples of any letter. For 2 and 3, I think they were looking for a different answer, as the lesson was on excluding characters, so for number 2 I would have went with something like \d+[^\w]*$. For number 3 I might have gone with something like [^a-z]*, which seems unnecessary, since yours does pretty much the same thing, ultimately excludes everything except the comma. It's not clear on number 4 if they also wanted you to exclude the slashes.