string resultString = null; try { resultString = Regex.Replace(subjectString, "(?<!^)[aeui](?!$)", ""); } catch (ArgumentException ex) { // Syntax error in the regular expression }