Use safer string methods rather than regexps