How to run a shell command inside a zsh-theme with Oh My Zsh
First, $() commands don't run inside of single-quotes. Changing your exterior quotes to &quot;&quot; should fix this. This also fixes the issue where the interior quotes were pre-maturely closing the string (as you can see from the syntax highlighting).
Second, the interior part seems to be broken on my computer since you're using a fixed regular expression. The server returns an IPv6 IP address for me, but that regular expression is looking for an IPv4 one. You can fix that by changing the regular expression (outside the scope of this question), but I'll suggest using jq. It lets you use a command line utility to parse JSON data. Again, if you're connecting to that server with an IPv4 address, then this change won't be needed (until your ISP in the future updates you to an IPv6 address).
I therefore end up with
&quot;%F{white}%M %n %y %j $(curl -s https://api.myip.com | jq .ip -r) %F{green}%2c%F{blue} [%f &quot;