If you insist on returning via the length of the first match, it’s gonna need a much longer regex, but I see no obvious reason why it would be impossible.
Retina does it, so .NET might have that as a built-in mode.
@Grimy To be more specific: I would consider any such regex, returning the result as a number of matches, to be in a completely different language than those I would simply call "Regex (ECMAScript)" or similar.
For example if I added a switch to display number of matches in my engine, the name of the language would need to be "RegexMathEngine (with -c switch)" or something like that (with whatever I decided to name the switch).
Similarly to how I would have to submit regex solutions for non-decision-problem sequence questions (where you're asked to display the first N numbers or the Nth number in the sequence).
Anyway, I don't get why you're so confident the totient function is possible. I think it may well be impossible.
It seems that some trick like what I did with abundant numbers may be possible, but I wouldn't count on it.
It is however, currently the best candidate I can think of for something that might be impossible but might be possible. Another one I liked the idea of, but think is much more likely to be impossible, is π(x) (prime counting function).
And "is this an Ulam number?" seems very impossible.