Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0a23cb4

Browse files
solved: regular expression matching
1 parent f28a03e commit 0a23cb4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

‎README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,13 @@ bool isPalindrome(int x) {
5757
return str == str.split('').reversed.join().toString();
5858
}
5959
60+
```
61+
62+
### Regular Expression Matching
63+
64+
```dart
65+
bool isMatch(String s, String p) {
66+
final RegExp regExp = RegExp(p);
67+
return regExp.stringMatch(s) == s;
68+
}
6069
```

‎regular_expression_matching.dart‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
void main(List<String> args) {
2+
List<List<String>> cases = [
3+
["aa", "a"],
4+
["aa", "a*"],
5+
["ab", ".*"],
6+
];
7+
8+
for (final testcase in cases) {
9+
print(isMatch(testcase[0], testcase[1]));
10+
}
11+
}
12+
13+
bool isMatch(String s, String p) {
14+
final RegExp regExp = RegExp(p);
15+
return regExp.stringMatch(s) == s;
16+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /