Modified regular expression solution