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.

Development Tools Introduction to Regular Expressions Regular Expressions Using Wildcard Characters

How to Match and Exclude for exercise 02

I am stuck in exercise 2. So far I am able to match but couldn't exclude numbers 4.

Here is what I was trying:


Test String:

1 a
2 a
3 a
4 a
5 a
8 a
9 b

4 c
4 E

Please any help would be appreciated.

Hi Zaid Khan ,

I come up with this solution

(?![4])\d+ \w

You can test and play with regex (here)[https://regex101.com/]

Hello, Ashish Mehra I tried your solution it's excluding perfectly but also not matching the 4 a string now.

2 Answers

I tried playing with Ashish Mehra RE and came up with

(?![4]\s[cE])\d+ \w

It matched and excluded as well.

Please share if someone came up with a different solution.

Zaid Khan

Awesome cheers,

Want to share https://regexr.com/ is a great tool which I forgot to mention earlier. It give description of each character in regex expression.

Thank you Ashish Mehra I will surely check this out, this seems very helpful.

Very late answer but

\d [ab]

works as well and is the simplest solution I can think of.