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

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:

[\d\sab]

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.