asRegex method
Retrieves a regular expression pattern from the map associated with the key
. If the key does not exist or the value cannot be parsed as a regex, returns the def
value.
key
The key in the map to retrieve the value from.
def
The default regex pattern to return if the key is not found or the value cannot be parsed. Defaults to r'(\w+)'
.
isBase64
Whether the regex pattern is base64 encoded. Defaults to true
.
multiline
Whether the regex pattern should be multiline. Defaults to true
.
Returns: A RegExp
object created from the pattern found in the map or def
if not found or cannot be parsed.
Implementation
RegExp asRegex(
String key, {
String def = r'(\w+)',
bool isBase64 = true,
bool multiline = true,
}) {
try {
if (isBase64) {
var regexBase64 = asString('regex');
var regexString = utf8.decode(base64Decode(regexBase64));
if (regexString.isNotEmpty) {
return RegExp(
regexString,
multiLine: multiline,
);
}
}
return RegExp(asString(key, def: r'(\w+)'));
} catch (e) {
return RegExp(r'(\w+)');
}
}