Replacing the use of regex with string parsing