import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?:http(s)?:\\/\\/(*SKIP))?(?(?<=(?::\\/\\/))(?:www\\.)?|(?:www\\.))((?:[\\w-]+(?:\\.[a-zA-Z0-9]{2,4}[\\/?]?)))([\\w\\d-=+&\\/]*)";
final String string = "www.regex101.com/\n"
+ "https://regex101.com/a\n"
+ "https://www.amazon.com/gp/yourstore/home/ref=topnav_ys_gw/002-2063622-5895250\n"
+ "<a href=\"http://www.regex101.com/\">regex101.com/</a>\n"
+ "Larry is survived by his wife, Sue of Waterloo, IA; two sons, Thomas (Peggy) Weber of Oak Park, IL, Ryan (Jaylene) Weber of Waterloo, IA; one daughter, Lori (Chris) Schutte of Jesup, IA; eight grandchildren, Scarlette and Jasper; Frank, Greta, and one on the way; Kalista, William, Ruby and Phoenix; three sisters, Sharon (Dan) Hambrock, Egan, MN, Judy (Jim) Meier, Tipton, IA, Marilyn (Victor) Kies, Cedar Rapids, IA; two brothers, Donald N. (Rose) Weber of Waterloo, Gerald W. “Gerry” (Shelly) Weber, Jesup; and two sisters-in-law, Brenda Weber of Jesup and Laura Weber of Raymond.\n\n"
+ "He is preceded in death by one son, Matthew (May 18, 1983), his parents, Clarence (2002) and Darlys (2008); two sisters, Janice (1958) and LuAnn (1965); two brothers, Ronald H. Weber (2014) and Dale C. Weber (2015) and his mother-in-law, Beverly Swyers (2013).\n\n"
+ "Funeral services were 10:30 a.m., Thursday, September 21, 2017, at Immaculate Conception Catholic Church, Gilbertville, IA with Rev. Henry Huber as celebrant with Deacon Al Weber assisting. Concelebrants also included Msgr. Ralph Simington, Fr. Lloyd Reuter and Fr. Jeffrey Dole. Music was by Bobbie Schares, organist, Todd Rohlfsen, soloist and the Resurrection Choir. Burial was at St. Joseph Catholic Cemetery, Raymond, IA. Casket Bearers were, Gerry Staebell, Steve Vogel, William Youngblut, Mike Reuter, Jim Breuer, Ted Monat, Adam Delagardelle, Jeremy Schmitz and Terry Hermeier.\n\n"
+ "Visitation was at Immaculate Conception Catholic Church in Gilbertville on Wednesday from 3-7 p.m.; where there was a Knights of Columbus Rosary at 4 p.m. and Vigil service at 7p.m. Visitation continued for an hour before services Thursday also at the church. Memorials may be directed to the family for charitable donations or a charity of the donor’s choice. Online condolences may be posted at www.White-MtHope.com\n"
+ "Larry is survived by his wife, Sue of Waterloo, IA; two sons, Thomas (Peggy) Weber of Oak Park, IL, Ryan (Jaylene) Weber of Waterloo, IA; one daughter, Lori (Chris) Schutte of Jesup, IA; eight grandchildren, Scarlette and Jasper; Frank, Greta, and one on the way; Kalista, William, Ruby and Phoenix; three sisters, Sharon (Dan) Hambrock, Egan, MN, Judy (Jim) Meier, Tipton, IA, Marilyn (Victor) Kies, Cedar Rapids, IA; two brothers, Donald N. (Rose) Weber of Waterloo, Gerald W. “Gerry” (Shelly) Weber, Jesup; and two sisters-in-law, Brenda Weber of Jesup and Laura Weber of Raymond.\n\n"
+ "He is preceded in death by one son, Matthew (May 18, 1983), his parents, Clarence (2002) and Darlys (2008); two sisters, Janice (1958) and LuAnn (1965); two brothers, Ronald H. Weber (2014) and Dale C. Weber (2015) and his mother-in-law, Beverly Swyers (2013).\n\n"
+ "Funeral services were 10:30 a.m., Thursday, September 21, 2017, at Immaculate Conception Catholic Church, Gilbertville, IA with Rev. Henry Huber as celebrant with Deacon Al Weber assisting. Concelebrants also included Msgr. Ralph Simington, Fr. Lloyd Reuter and Fr. Jeffrey Dole. Music was by Bobbie Schares, organist, Todd Rohlfsen, soloist and the Resurrection Choir. Burial was at St. Joseph Catholic Cemetery, Raymond, IA. Casket Bearers were, Gerry Staebell, Steve Vogel, William Youngblut, Mike Reuter, Jim Breuer, Ted Monat, Adam Delagardelle, Jeremy Schmitz and Terry Hermeier.\n\n"
+ "Visitation was at Immaculate Conception Catholic Church in Gilbertville on Wednesday from 3-7 p.m.; where there was a Knights of Columbus Rosary at 4 p.m. and Vigil service at 7p.m. Visitation continued for an hour before services Thursday also at the church. Memorials may be directed to the family for charitable donations or a charity of the donor’s choice. Online condolences may be posted at www.White-MtHope.com\n"
+ "Larry is survived by his wife, Sue of Waterloo, IA; two sons, Thomas (Peggy) Weber of Oak Park, IL, Ryan (Jaylene) Weber of Waterloo, IA; one daughter, Lori (Chris) Schutte of Jesup, IA; eight grandchildren, Scarlette and Jasper; Frank, Greta, and one on the way; Kalista, William, Ruby and Phoenix; three sisters, Sharon (Dan) Hambrock, Egan, MN, Judy (Jim) Meier, Tipton, IA, Marilyn (Victor) Kies, Cedar Rapids, IA; two brothers, Donald N. (Rose) Weber of Waterloo, Gerald W. “Gerry” (Shelly) Weber, Jesup; and two sisters-in-law, Brenda Weber of Jesup and Laura Weber of Raymond.\n\n"
+ "He is preceded in death by one son, Matthew (May 18, 1983), his parents, Clarence (2002) and Darlys (2008); two sisters, Janice (1958) and LuAnn (1965); two brothers, Ronald H. Weber (2014) and Dale C. Weber (2015) and his mother-in-law, Beverly Swyers (2013).\n\n"
+ "Funeral services were 10:30 a.m., Thursday, September 21, 2017, at Immaculate Conception Catholic Church, Gilbertville, IA with Rev. Henry Huber as celebrant with Deacon Al Weber assisting. Concelebrants also included Msgr. Ralph Simington, Fr. Lloyd Reuter and Fr. Jeffrey Dole. Music was by Bobbie Schares, organist, Todd Rohlfsen, soloist and the Resurrection Choir. Burial was at St. Joseph Catholic Cemetery, Raymond, IA. Casket Bearers were, Gerry Staebell, Steve Vogel, William Youngblut, Mike Reuter, Jim Breuer, Ted Monat, Adam Delagardelle, Jeremy Schmitz and Terry Hermeier.\n\n"
+ "Visitation was at Immaculate Conception Catholic Church in Gilbertville on Wednesday from 3-7 p.m.; where there was a Knights of Columbus Rosary at 4 p.m. and Vigil service at 7p.m. Visitation continued for an hour before services Thursday also at the church. Memorials may be directed to the family for charitable donations or a charity of the donor’s choice. Online condolences may be posted at www.White-MtHope.com\n"
+ "Larry is survived by his wife, Sue of Waterloo, IA; two sons, Thomas (Peggy) Weber of Oak Park, IL, Ryan (Jaylene) Weber of Waterloo, IA; one daughter, Lori (Chris) Schutte of Jesup, IA; eight grandchildren, Scarlette and Jasper; Frank, Greta, and one on the way; Kalista, William, Ruby and Phoenix; three sisters, Sharon (Dan) Hambrock, Egan, MN, Judy (Jim) Meier, Tipton, IA, Marilyn (Victor) Kies, Cedar Rapids, IA; two brothers, Donald N. (Rose) Weber of Waterloo, Gerald W. “Gerry” (Shelly) Weber, Jesup; and two sisters-in-law, Brenda Weber of Jesup and Laura Weber of Raymond.\n\n"
+ "He is preceded in death by one son, Matthew (May 18, 1983), his parents, Clarence (2002) and Darlys (2008); two sisters, Janice (1958) and LuAnn (1965); two brothers, Ronald H. Weber (2014) and Dale C. Weber (2015) and his mother-in-law, Beverly Swyers (2013).\n\n"
+ "Funeral services were 10:30 a.m., Thursday, September 21, 2017, at Immaculate Conception Catholic Church, Gilbertville, IA with Rev. Henry Huber as celebrant with Deacon Al Weber assisting. Concelebrants also included Msgr. Ralph Simington, Fr. Lloyd Reuter and Fr. Jeffrey Dole. Music was by Bobbie Schares, organist, Todd Rohlfsen, soloist and the Resurrection Choir. Burial was at St. Joseph Catholic Cemetery, Raymond, IA. Casket Bearers were, Gerry Staebell, Steve Vogel, William Youngblut, Mike Reuter, Jim Breuer, Ted Monat, Adam Delagardelle, Jeremy Schmitz and Terry Hermeier.\n\n"
+ "Visitation was at Immaculate Conception Catholic Church in Gilbertville on Wednesday from 3-7 p.m.; where there was a Knights of Columbus Rosary at 4 p.m. and Vigil service at 7p.m. Visitation continued for an hour before services Thursday also at the church. Memorials may be directed to the family for charitable donations or a charity of the donor’s choice. Online condolences may be posted at www.White-MtHope.com\n"
+ "Larry is survived by his wife, Sue of Waterloo, IA; two sons, Thomas (Peggy) Weber of Oak Park, IL, Ryan (Jaylene) Weber of Waterloo, IA; one daughter, Lori (Chris) Schutte of Jesup, IA; eight grandchildren, Scarlette and Jasper; Frank, Greta, and one on the way; Kalista, William, Ruby and Phoenix; three sisters, Sharon (Dan) Hambrock, Egan, MN, Judy (Jim) Meier, Tipton, IA, Marilyn (Victor) Kies, Cedar Rapids, IA; two brothers, Donald N. (Rose) Weber of Waterloo, Gerald W. “Gerry” (Shelly) Weber, Jesup; and two sisters-in-law, Brenda Weber of Jesup and Laura Weber of Raymond.\n\n"
+ "He is preceded in death by one son, Matthew (May 18, 1983), his parents, Clarence (2002) and Darlys (2008); two sisters, Janice (1958) and LuAnn (1965); two brothers, Ronald H. Weber (2014) and Dale C. Weber (2015) and his mother-in-law, Beverly Swyers (2013).\n\n"
+ "Funeral services were 10:30 a.m., Thursday, September 21, 2017, at Immaculate Conception Catholic Church, Gilbertville, IA with Rev. Henry Huber as celebrant with Deacon Al Weber assisting. Concelebrants also included Msgr. Ralph Simington, Fr. Lloyd Reuter and Fr. Jeffrey Dole. Music was by Bobbie Schares, organist, Todd Rohlfsen, soloist and the Resurrection Choir. Burial was at St. Joseph Catholic Cemetery, Raymond, IA. Casket Bearers were, Gerry Staebell, Steve Vogel, William Youngblut, Mike Reuter, Jim Breuer, Ted Monat, Adam Delagardelle, Jeremy Schmitz and Terry Hermeier.\n\n"
+ "Visitation was at Immaculate Conception Catholic Church in Gilbertville on Wednesday from 3-7 p.m.; where there was a Knights of Columbus Rosary at 4 p.m. and Vigil service at 7p.m. Visitation continued for an hour before services Thursday also at the church. Memorials may be directed to the family for charitable donations or a charity of the donor’s choice. Online condolences may be posted at \n"
+ "L\n\n";
final String subst = "<a href=\"http\\1://\\0\">\\2</a>";
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