removeEnclosingQuotes method
Trims all forms of quotation marks from start of the String.
Trims all forms of quotation marks from end of the String if the string starts with the same quotation mark.
Only selects for U+0022 and U+0027, so call normalizeQuotes first.
Implementation
String removeEnclosingQuotes() {
final term = trim();
final startingQuote = RegExp('(?<=^)[\'"]+').firstMatch(term)?[0];
return (startingQuote != null)
? term.replaceAll(
RegExp('(?<=^)$startingQuote|$startingQuote(?=\$)'), '')
: term;
}