import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(PageTitle = \"([^\"]*)\")(.*)(<title>)([^<]*)(<\\/title>)(.*)(<h1 id=\"page-title\" class=\"font-36\">)([^<]*)(<\\/h1>)(.*)$";
final String string = "<!-- and this include too -->\n"
+ "Must include all this too\n"
+ "<%\n"
+ "PageTitle = \"Member Access\" \n\n"
+ "MetaDescription = \"There are a number of degree and education paths that can lead an individual to a career in toxicology. This page is designed to provide those considering a career in toxicology with information on the profession, schooling needed, and more. The content of this page was originally developed as a printed publication called Resource Guide to Careers in Toxicology\"\n\n"
+ "Keywords = \"SOT, Toxicology, Careers, Resource Guide\"\n\n"
+ "SocialImage = \"http://209.183.221.233/images/sot_logo.png\"\n\n"
+ "SocialImageDescription = \"SOT logo\"\n\n"
+ "SocialURL = \"http://209.183.221.233/login.asp\"\n\n\n\n"
+ "%>\n"
+ "<!doctype html>\n"
+ "<html dir=\"ltr\" lang=\"en\">\n"
+ "<head>\n"
+ "<meta charset=\"UTF-8\">\n\n"
+ "<!-- Meta Tags -->\n"
+ "<meta name=\"description\" content=\"There are a number of degree and education paths that can lead an individual to a career in toxicology. This page is designed to provide those considering a career in toxicology with information on the profession, schooling needed, and more. The content of this page was originally developed as a printed publication called Resource Guide to Careers in Toxicology\">\n"
+ "<meta name=\"keywords\" content= \"SOT, Toxicology, Careers, Resource Guide\">\n"
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0 shrink-to-fit=no\">\n"
+ "<meta name=\"author\" content=\"Society of Toxicology\" />\n"
+ "<meta name =\"robots\" content=\"index\" >\n\n"
+ "<!-- Twitter and Facebook Social media tags -->\n"
+ "<meta property=\"fb:app_id\" content=\"309282950004135\" />\n"
+ "<meta property=\"og:title\" content=\"New Experiences in Toxicology Program\" >\n"
+ "<meta property=\"og:description\" content=\"There are a number of degree and education paths that can lead an individual to a career in toxicology. This page is designed to provide those considering a career in toxicology with information on the profession, schooling needed, and more. The content of this page was originally developed as a printed publication called Resource Guide to Careers in Toxicology\">\n"
+ "<meta property=\"og:image\" content=\"http://209.183.221.233/images/sot_logo.png\">\n"
+ "<meta property=\"og:url\" content=\"http://209.183.221.233/education/st/next.asp\">\n"
+ "<meta property=\"og:type\" content=\"website\" />\n\n"
+ "<!-- Non-Essential, But Recommended -->\n"
+ "<meta property=\"og:site_name\" content=\"Society of Toxicology\">\n"
+ "<meta name=\"twitter:card\" content=\"summary_large_image\">\n"
+ "<meta name=\"twitter:image:alt\" content= \"SOT logo\">\n"
+ "<meta name=\"twitter:creator\" content=\"@SOToxicology\" />\n\n"
+ "<!-- Non-Essential, But Required for Analytics -->\n"
+ "<meta name=\"twitter:site\" content=\"@SOToxicology\">\n\n"
+ "<!-- Follow Facebook's recommendation of a minimum dimension of 1200x630 pixels and an aspect ratio of 1.91:1, but adhere to Twitter's file size requirement of less than 1MB.--> \n\n"
+ "<!-- Page Title -->\n"
+ "<title>New Experiences in Toxicology Program</title>\n\n\n"
+ "<!-- #include virtual=\"/_includes/header_newsite_trt.asp\" --> \n"
+ " \n"
+ " \n"
+ "<div id=\"main\" class=\"main-content\">\n"
+ " <section class=\"inner-header divider layer-overlay overlay-dark-4\" data-bg-img=\"/images/_interior-banners/About-banner.jpg\" style=\"background-image: url('/images/_interior-banners/About-banner.jpg'); \">\n"
+ " <div class=\"container pt-30 pb-30\"> \n"
+ " <!-- Section Content -->\n"
+ " <div class=\"section-content\">\n"
+ " <div class=\"row\">\n"
+ " <div class=\"col-md-6\">\n"
+ " <h1 id=\"page-title\" class=\"font-36\">New Experiences in Toxicology Program</h1>\n"
+ " <ol class=\"breadcrumb text-left mt-10 white\">\n"
+ " <li class=\"active\">New Experiences in Toxicology Program</li>\n"
+ " </ol>\n"
+ " </div>\n"
+ " </div>\n"
+ " </div>\n"
+ " </div>\n"
+ " </section>\n"
+ "<!-- #include virtual=\"/_includes/social-buttons.asp\" --> \n\n"
+ "<!-- Indvidual Page Content Below -->\n\n"
+ "<!-- #include virtual=\"/_global/SOTLogin.asp\" -->\n"
+ "<!-- Section: Paragraph --->\n"
+ " <section>\n"
+ " <div class=\"container \">\n"
+ " <div class=\"section-content\">\n"
+ "<CENTER>\n"
+ " <TABLE width=500>\n"
+ " <TR> \n"
+ " <TD height=\"0\" width=\"226\"></TD>\n"
+ " <TD width=\"108\"></TD>\n"
+ " </TR>\n"
+ " <TR>\n"
+ " <TD height=\"211\" valign=\"top\"> \n"
+ " <TABLE >\n"
+ " <TR>\n"
+ " <TD align=center height=\"185\">\n"
+ " <noscript>\n"
+ " Javascript not enabled. <BR>Membership functions are not available.\n"
+ " </noscript>\n"
+ " \n"
+ " <% If Request.Cookies(\"sot-session-id\") <> \"\" Then %>\n"
+ " <h3>You are now logged in.<br>Please wait for the page to be redirected.</h3>\n"
+ " <meta http-equiv='refresh' content='1;url=/'>\n"
+ " <% End If %>\n"
+ " \n"
+ " </font></TD>\n"
+ " </TR>\n"
+ " </TABLE>\n"
+ " \n"
+ " </TD>\n"
+ " <TD height=\"211\"></TD>\n"
+ " </TR>\n"
+ " </TABLE>\n"
+ "</CENTER>\n\n"
+ " </div>\n"
+ " <!-- /columns --> \n"
+ " \n"
+ " </div>\n"
+ " </section>\n"
+ " <!-- /section Full paragraph ends--> \n"
+ " \n\n"
+ "<!-- #include virtual=\"/_includes/footer.asp\" --> ";
final String subst = "$1$3$4$2$6$7$8$2$10$11";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
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