You're probably running a shell other than bash when sourcing that file, which is why you are having an issue. I'm guessing that you are trying to source it from a zsh shell.
$ zsh -c 'if [[ $i =~ ^\~.*|^\/.* ]]; then echo ok; fi'
zsh:1: parse error near `|'
Since programmatic completion is very shell-specific, it's unlikely that you will be able to use a completion script written for bash in the zsh shell, even if you make the syntax zsh-compatible.
Unrelated: The regular expression is testing whether the string in the variable i starts with a slash or a tilde. That test (and the test on $configfile) can portably be done this way:
case $i in
[~/]*)
# do nothing
;;
*)
case $configfile in
/etc/ssh*)
i=/etc/ssh/$i
;;
*)
i=$HOME/.ssh/$i
esac
esac
Or, the regular expressions could at least be cleaned up as ^[~/] and ^/etc/ssh, respectively. Note that there is absolutely no reason to escape slashes or to match the tail end of the string with .*.
echo $0)