Reputation: 549
This question is purely for fun. Are regular expressions powerful enough to actually add any two positive integers? By that I mean replacing the string a+b
with the numerical value of a+b.
I realize this depends on the notation we choose for numbers. Certainly if we write them as tally marks the regex is easy, just remove the plus symbol. How about numbers written in binary? Any way to do it, or convincing reasons why it is impossible?
Upvotes: 4
Views: 4911
Reputation: 133629
I would say no if we're talking about basic ones, since regex language is not Turing complete, maybe with powerful exsensions (eg recursive substitutions or similar tools)..
Upvotes: 0
Reputation: 301527
Since this is for fun and to see power of regex:
Find prime numbers using regex - http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/
Upvotes: 1