copyWith method

RegExp copyWith({
  1. String? pattern,
  2. bool? multiLine,
  3. bool? caseSensitive,
  4. bool? unicode,
  5. bool? dotAll,
})

A default implementation of copyWith for RegExp.

This method is used to create a new RegExp with the same properties of the original, but with the given values replaced.

Example:

final regex = RegExp(r'(?<name>\w+)');
final newRegex = regex.copyWith(caseSensitive: false);

Implementation

RegExp copyWith({
  String? pattern,
  bool? multiLine,
  bool? caseSensitive,
  bool? unicode,
  bool? dotAll,
}) {
  return RegExp(
    pattern ?? this.pattern,
    multiLine: multiLine ?? isMultiLine,
    caseSensitive: caseSensitive ?? isCaseSensitive,
    unicode: unicode ?? isUnicode,
    dotAll: dotAll ?? isDotAll,
  );
}