“abc def” should match the following regex because “abc” and “def” both have 3 characters
/([a-z]*) ([a-z]*){\1.length}/
Is there a way to do this in Ruby?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The set of strings you describe do not form a regular language. It cannot be matched by a regular expression. It’s one of the classic examples of languages that can’t be matched with a regular expression (another is testing for matching parentheses).
Just compare the lengths of the two strings in ordinary code.