1

I've been doing some reading on regular expressions and thought I had everything covered, until recently.

I've had to filter out all strings of length 5 which end with the letter t and contain at least one dot inside. The problem arises when I try to limit the size of the string. It works just fine when I first filter out all strings of size 5 and then additionally do the filtering in accordance with the occurrence of a dot inside, but it's a hassle.

What would be the best way to accomplish this using one regex?

Thanks for any answers in advance!

  • Please post your code so we can look at it. – rahul Apr 29 '15 at 17:38
1

When you have an and of 2 constraints it is easier to work one at the time. Example:

grep '^....t$' | grep '\.'

or

perl -nlE '/^....t/ and /\./ and say '

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.