Improve regex. Remove unnecessary trim()s. Avoid try-catch.