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 Matching Specific Characters

Kieran Barker
Kieran Barker
15,028 Points

How can I match 'ladybug' and 'fading rug!' in RegEx only using the '?', '.' or '[]' special characters?

I'm following along with the 'Regular Expressions in JavaScript' course. How can I match 'ladybug' and 'fading rug!' only using the '?', '.' and '[]' special RegEx characters? It should be possible with these alone but I can't figure it out. Thanks :)

3 Answers

Steven Parker
Steven Parker
229,644 Points

With regex, there will usually be more than one way to create a match. Here's one example using only ? and []:
:point_right: [lf]ad[yi]n?g? ?[br]ug!?
And here's another one that is more concise (and less exclusive) using only . and ?:
:point_right: .ad.n?g? ?.ug!?

This one was pretty difficult! Thanks for the help Steven. I kept getting the ing rug! but could get anything else preceding that. Thanks!