The `toString` method in Dart's `RegExp` class returns a string representation of the `RegExp` object.
The syntax of RegExp.toString() method is:
String toString()
This toString() method of RegExp returns a string representation of this object.
RegExp.toString() returns value of type String
.
In this example,
void main() {
RegExp regex = RegExp('hello');
print('String representation of regex: ${regex.toString()}');
}
String representation of regex: RegExp/hello/
In this example,
void main() {
RegExp regex = RegExp('[0-9]+');
print('String representation of regex: ${regex.toString()}');
}
String representation of regex: RegExp/[0-9]+/
In this example,
void main() {
RegExp regex = RegExp('[a-zA-Z]+');
print('String representation of regex: ${regex.toString()}');
}
String representation of regex: RegExp/[a-zA-Z]+/
In this Dart tutorial, we learned about toString() method of RegExp: the syntax and few working examples with output and detailed explanation for each example.