The `hashCode` property in Dart's `RegExp` class returns the hash code for an object.
The syntax of RegExp.hashCode property is:
int hashCode
This hashCode property of RegExp the hash code for this object.
RegExp.hashCode returns value of type int
.
In this example,
void main() {
RegExp pattern = RegExp('hello');
int hash = pattern.hashCode;
print('Hash code: $hash');
}
Hash code: 451537081
In this example,
void main() {
RegExp pattern = RegExp('[0-9]+');
int hash = pattern.hashCode;
print('Hash code: $hash');
}
Hash code: 512605508
In this example,
void main() {
RegExp pattern = RegExp(r'\w+');
int hash = pattern.hashCode;
print('Hash code: $hash');
}
Hash code: 509502384
In this Dart tutorial, we learned about hashCode property of RegExp: the syntax and few working examples with output and detailed explanation for each example.