rs, 31 bytes
^(google)|(.*)$/((^^\2))^^(1\1)
In rs, ^^
is the length and repetition operator. Used in the unary form, it will get the length of the following text (^^\2)
. Used in binary form, it will repeat the LHS RHS times ((^^\2))^^(1\1)
.
Take the input bing
. The input is not google
, so the second group will match, not the first. Once the substitutions take place, the result is ((^^bing))^^(1)
. ^^
gets the length to result in (4)^^(1)
, and the result gets repeated 1 time to result in 4
.
However, if the input is google
, the first group will match. That will result in ((^^))^^(1google)
after substitutions. ^^
will just get the length of the empty string (0), so the result after ^^
is applied will be (0)^^(1google)
. Now the repetition operator can do its work...or not. See it will try to repeat 0
1google
times. As 1google
isn't a number, the output will be:
Traceback (most recent call last):
File "c callback", line 6, in <module>
File "<string>", line 5, in <module>
File "<string>", line 167, in main
File "<string>", line 125, in run
File "<string>", line 72, in expand
ValueError: invalid literal for int() with base 10: '1google'
Live demo. (Put the input text in the box at the bottom left.)