You probably want Regexp.escape
:
service = properties.match(/^com\.google\.(#{Regexp.escape(serviceName)})\.public$/)
Additionally, you had surrounded your inclusion of serviceName
with a [...]+
, which means more than one character from this list of characters in [...]
.
E.g. This regexp [commonapi]+
accepts moconaipimdconn
, or indeed any length string that contained some characters from the service name you actually wanted to capture.