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 trialtjeiosajfdksl
Courses Plus Student 8,981 PointsI can not match #4 please help
My regex is :
/[lf]ad[yi][bn][ug]g?[ rug!]?/
it is supposed to match both these strings but does not match second one:
ladybug fading rug!
How to get the regex to also match : fading rug!
7 Answers
Nathan Brenner
35,844 PointsAnother possible solution: /[fl]adi?n?[gy] ?[br]ug!?/
As far as figuring out how to get from the first case to the second, I wrote the first case into the regex expression, then I added another test case and changed the regex.
For example, started with /ladybug/
and only testing for ladybug
and fading rug!
, ladybug passes but fading rug ! fails, so I added another test case fadybug
and changed the regex to [fl]adybug
. I ended up added 6 additional test cases. To go a step further, I would want to keep changing the regex so it only matches the first two cases.
Chirag Mehta
15,332 Points[fl]ad[iy]n?g? ?[br]ug!?
L Haney
Front End Web Development Techdegree Student 10,263 PointsHere's my answer:
/[lf]adi?n?[gy][ ]?[br]ug!?/
Andrew Phythian
19,747 PointsHere's mine...
/[lf]ad[yi]b?[un]g ?r?u?g?!?/
Martin Bort
851 Pointsmy answer was
/[lf]adi?n?g?y? ?[br]ug!?/
bare in mind, only one character inside a square bracket will ever be used.
so if you have [rug!]
like you have, it will only try to match either 'r', 'u' or 'g'. Never the whole string 'rug'
Vivian Rydh
8,873 Points[lf]ad[yi][bn][ug][g ]r?u?g?!?
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?!?