Given a decimal number N as a string of digits, how do I check if it\'s divisible by M using regular expressions only, without con
As interesting as this question is, I don't believe it's possible for anything other than the "obvious" ones you list.
Most of the divisibility rules require mathematical manipulation.
You could use a lookahead to test the string for more than one requirement, so that you can combine pairs of the "obvious" ones together (2 x 3, 3 x 5, etc.):
Matching a 6-letter word is easy with
\b\w{6}\b. Matching a word containing "cat" is equally easy:\b\w*cat\w*\b.Combining the two, we get:
(?=\b\w{6}\b)\b\w*cat\w*\bAnalyze this regular expression with RegexBuddy. Easy! Here's how this works. At each character position in the string where the regex is attempted, the engine will first attempt the regex inside the positive lookahead. This sub-regex, and therefore the lookahead, matches only when the current character position in the string is at the start of a 6-letter word in the string. If not, the lookahead will fail, and the engine will continue trying the regex from the start at the next character position in the string.