We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The tests here dont cover a lot of overinclusion mistakes you could make with regex here. for instance, this regex will pass all tests:
/^[MDE][rs]{1,2}\.[a-zA-Z]*$/
but this would also match "Ess", "Err", "Msr", Mss", "Mrr", etc. as well as the legitimate prefixes. A better pattern could be something like:
/^(Mr?s|[MDE]r)\.[a-zA-Z]*$/
you could also or together each possible prefix, which would be less performant but more readable, which could be preferrable if optimization isn't needed.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 7: Regular Expressions II
You are viewing a single comment's thread. Return to all comments →
The tests here dont cover a lot of overinclusion mistakes you could make with regex here. for instance, this regex will pass all tests:
/^[MDE][rs]{1,2}\.[a-zA-Z]*$/
but this would also match "Ess", "Err", "Msr", Mss", "Mrr", etc. as well as the legitimate prefixes. A better pattern could be something like:/^(Mr?s|[MDE]r)\.[a-zA-Z]*$/
you could also or together each possible prefix, which would be less performant but more readable, which could be preferrable if optimization isn't needed.