Skip to content

Commit c172d1e

Browse files
authored
Create RegEx to extract URLs from a String.dart
1 parent 2acc773 commit c172d1e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
void main() {
2+
final text = """My website url: https://blasanka.github.io/
3+
Google search using: www.google.com, social media is facebook.com, http://example.com/method?param=flutter
4+
stackoverflow.com is my greatest website. DartPad share: https://github.com/dart-lang/dart-pad/wiki/Sharing-Guide see this example and edit it here https://dartpad.dev/3d547fa15849f9794b7dbb8627499b00""";
5+
6+
RegExp exp = new RegExp(r'(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-?=%.]+');
7+
Iterable<RegExpMatch> matches = exp.allMatches(text);
8+
9+
matches.forEach((match) {
10+
print(text.substring(match.start, match.end));
11+
});
12+
}

0 commit comments

Comments
 (0)