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 55bb9f0

Browse files
solved: wildcard matching
1 parent bc3c6a2 commit 55bb9f0

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

‎src/wildcard_matching.dart‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,26 @@ void main(List<String> args) {
1313
}
1414

1515
bool isMatch(String s, String p) {
16-
final RegExp regExp = RegExp(p.replaceAll('*', '^g\.*').replaceAll('?', '^g\.?'));
17-
print(regExp.stringMatch(s));
18-
return regExp.stringMatch(s) == s;
16+
if (p.replaceAll("*", "").length > s.length) return false;
17+
18+
List<bool> flags = List.generate(s.length + 1, (index) => false);
19+
flags.first = true;
20+
for (int i = 1; i < s.length; ++i) {
21+
flags[i] = false;
22+
}
23+
24+
for (int i = 1; i <= p.length; ++i) {
25+
String char = p[i - 1];
26+
if (char == '*') {
27+
for (int j = 1; j <= s.length; ++j) {
28+
flags[j] = flags[j - 1] || flags[j];
29+
}
30+
} else {
31+
for (int j = s.length; j >= 1; --j) {
32+
flags[j] = flags[j - 1] && (char == '?' || char == s[j - 1]);
33+
}
34+
}
35+
flags[0] = flags[0] && char == '*';
36+
}
37+
return flags[s.length];
1938
}

0 commit comments

Comments
(0)

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