whitelist function

String whitelist(
  1. String str,
  2. String chars
)

remove characters that do not appear in the whitelist.

The characters are used in a RegExp and so you will need to escape some chars.

Implementation

String whitelist(String str, String chars) =>
    str.replaceAll(RegExp('[^$chars]+'), '');