Refactor strings.js functions to reuse functions and regexs