Skip to content

Instantly share code, notes, and snippets.

@Blasanka
Last active December 22, 2019 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Blasanka/3d547fa15849f9794b7dbb8627499b00 to your computer and use it in GitHub Desktop.
Save Blasanka/3d547fa15849f9794b7dbb8627499b00 to your computer and use it in GitHub Desktop.
Regular expression to find urls in String
void main() {
final text = """My website url: https://blasanka.github.io/
Google search using: www.google.com, social media is facebook.com, http://example.com/method?param=flutter
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 """;
RegExp exp = new RegExp(r'(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-?=%.]+');
Iterable<RegExpMatch> matches = exp.allMatches(text);
matches.forEach((match) {
print(text.substring(match.start, match.end));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment