Dart RegExp pattern
Syntax & Examples
RegExp.pattern property
The `pattern` property in Dart's `RegExp` class retrieves the source regular expression string used to create the `RegExp` object.
Syntax of RegExp.pattern
The syntax of RegExp.pattern property is:
String pattern
This pattern property of RegExp the source regular expression string used to create this RegExp
.
Return Type
RegExp.pattern returns value of type String
.
✐ Examples
1 Pattern Retrieval
In this example,
- We create a regular expression `regex` with a specific pattern.
- We retrieve and print the `pattern` property of the regex.
Dart Program
void main() {
RegExp regex = RegExp('^hello');
print('regex.pattern: ${regex.pattern}');
}
Output
regex.pattern: ^hello
2 Pattern Retrieval
In this example,
- We create a regular expression `regex` with a specific pattern.
- We retrieve and print the `pattern` property of the regex.
Dart Program
void main() {
RegExp regex = RegExp('Hello');
print('regex.pattern: ${regex.pattern}');
}
Output
regex.pattern: Hello
3 Pattern Retrieval
In this example,
- We create a regular expression `regex` with a specific pattern.
- We retrieve and print the `pattern` property of the regex.
Dart Program
void main() {
RegExp regex = RegExp('World');
print('regex.pattern: ${regex.pattern}');
}
Output
regex.pattern: World
Summary
In this Dart tutorial, we learned about pattern property of RegExp: the syntax and few working examples with output and detailed explanation for each example.