isValidRegex static method

bool isValidRegex(
  1. String pattern
)

Check if a pattern is a valid regex when prefixed with "regex:".

Implementation

static bool isValidRegex(String pattern) {
  if (!pattern.startsWith('regex:')) return true;
  try {
    RegExp(pattern.substring(6));
    return true;
  } catch (_) {
    return false;
  }
}