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 trialKieran Barker
15,028 PointsHow 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
231,248 PointsWith regex, there will usually be more than one way to create a match. Here's one example using only ? and []:
[lf]ad[yi]n?g? ?[br]ug!?
And here's another one that is more concise (and less exclusive) using only . and ?:
.ad.n?g? ?.ug!?
Greg Witt
27,133 PointsThis one was pretty difficult! Thanks for the help Steven. I kept getting the ing rug!
but could get anything else preceding that. Thanks!
Ozaveshe Balogun
Front End Web Development Techdegree Student 20,459 PointsI know this is old but this my own solution: [lf]ad[yi][bn][ug] ?r?u?g!?
or f?a?d?.....ug!?
or .ad.n?g? ?.ug!?
or .ad.n?...u?g?!?