import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "https?\\:\\/\\/(www.)?([a-z\\.A-Z\\-]+)\\/.*";
final String string = "https://thenextweb.com/dd/2014/04/08/ux-designers-side-drawer-navigation-costing-half-user-engagement/\n"
+ "https://developer.android.com/training/implementing-navigation/nav-drawer.html\n"
+ "http://www.viralandroid.com/2015/09/android-sliding-menu-with-webview.html\n"
+ "https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&cad=rja&uac…Android&usg=AFQjCNFRk6d5AhBfonGM106Sad2tjoBT7g&sig2=kiMOjbXGWDcWRLpLOvyYQQ\n"
+ "https://github.com/twbs/bootstrap/issues/4550\n"
+ "https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=6&cad=rja&uac…ypes%2F&usg=AFQjCNHRDjZYkePYfSuVIkV9e4XLWM0V_g&sig2=_jN849JNw4Zbp2s3Anlzgw\n"
+ "http://stackoverflow.com/questions/24463890/open-webview-when-item-in-the-side-slide-menu-is-clicked\n"
+ "https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=8&cad=rja&uac…s-popup&usg=AFQjCNFtDDELoRlF3_9SuoyJJ2kzZsDrDw&sig2=54H1u1WQd2NG0aywd6G4SQ\n"
+ "https://support.proto.io/hc/en-us/community/posts/207856878-Sliding-sidebar-menu-s-links-do-not-work-on-Android-app\n"
+ "https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=10&cad=rja&ua…b265b49&usg=AFQjCNEgo2JyzndfiLfH9duieqVd71CsVA&sig2=txF-3ZgdzHydpJJJ2BwT5Q\n"
+ "https://developer.chrome.com/multidevice/android/customtabs\n"
+ "http://www.howtogeek.com/237951/how-to-add-website-links-to-the-windows-10-start-menu/\n"
+ "https://paul.kinlan.me/deep-app-linking-on-android-and-chrome/\n"
+ "https://developers.google.com/apps-script/guides/dialogs\n"
+ "https://material.io/guidelines/patterns/navigation-drawer.html\n"
+ "https://help.shopify.com/manual/sell-online/online-store/menus-and-links\n"
+ "https://books.google.com/books?id=IAVnDQAAQBAJ&pg=PT129&lpg=PT129&dq=androi…PsnBph0QJXDzjUY&hl=en&sa=X&ved=0ahUKEwi5_6G-9pXSAhXHurwKHc6RCQEQ6AEIgwEwEA\n"
+ "https://lmjabreu.com/post/why-and-how-to-avoid-hamburger-menus\n"
+ "http://stacktips.com/tutorials/android/navigation-drawer-android-example\n"
+ "https://www.npmjs.com/package/cordova-universal-links-plugin\n"
+ "https://support.wunderlist.com/customer/portal/articles/1767713\n"
+ "https://www.thepolyglotdeveloper.com/2014/12/open-dynamic-links-using-cordova-inappbrowser/\n"
+ "http://www.infoworld.com/article/2610416/web-browsers/web-browsers-50-tips-and-tricks-for-chrome-power-users.html\n"
+ "https://vivaldi.com/?lang=en_US\n"
+ "http://www.androidpolice.com/2016/01/20/google-android-app-can-now-open-links-in-chrome-custom-tabs-after-latest-update/\n"
+ "https://forum.ionicframework.com/t/external-links-in-side-menu-not-working/58384\n"
+ "http://dolphin.com/dolphin-for-android-phone-faqs/\n"
+ "https://www.facebook.com/business/help/312169205649942\n"
+ "http://blog.teamtreehouse.com/add-navigation-drawer-android\n"
+ "http://forums.androidcentral.com/android-apps/593611-how-force-android-open-facebook-links-facebook-app.html\n"
+ "https://plaid.com/docs/quickstart/\n"
+ "https://motorola-global-portal.custhelp.com/app/answers/prod_answer_detail/a_id/109551/p/30,6720,9583\n"
+ "http://blog.ionic.io/deeplinking-in-ionic-apps/\n"
+ "https://help.evernote.com/hc/en-us/articles/209004637-How-to-create-shortcuts-for-frequently-accessed-notes-notebooks-and-searches\n"
+ "http://www.jqueryscript.net/tags.php?/side%20menu/\n"
+ "https://community.box.com/t5/Account-Information/How-To-Disable-Plugins-Add-Ons-Extensions-In-Multiple-Browsers/ta-p/19\n"
+ "https://support.mozilla.org/en-US/kb/using-tabs-firefox-android\n"
+ "http://semantic-ui.com/modules/sidebar.html\n"
+ "https://docs.citrix.com/en-us/xenmobile-apps/10/secure-web.html\n"
+ "https://www.cnet.com/how-to/how-to-request-desktop-version-of-a-web-site-in-chrome-for-android/\n"
+ "http://mmenu.frebsite.nl/\n"
+ "http://tiddlywiki.com/\n"
+ "http://callmenick.com/post/slide-and-push-menus-with-css3-transitions\n"
+ "https://www.lullabot.com/articles/navigation-and-deep-linking-with-react-native\n"
+ "http://www.computerworld.com/article/2474114/android/4-hidden-settings-to-make-chrome-for-android-even-better.html\n"
+ "http://help.tune.com/marketing-console/creating-and-using-deeplink-urls/\n"
+ "https://codepen.io/zavoloklom/pen/dIgco\n"
+ "https://www.smashingmagazine.com/2012/06/responsive-menus-enhancing-navigation-on-mobile-websites/\n"
+ "https://get.slack.help/hc/en-us/articles/205166337-Customize-your-Slack-theme\n"
+ "https://code.tutsplus.com/tutorials/mobile-web-quick-tip-phone-number-links--mobile-7667";
final String subst = "$2";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html