我的正则表达式:(?s)((?:\s*out\.print(?:ln)?\("[^"\\]*(?:\\.[^"\\]*)*"\);)+)
我的代码:
Pattern lp = Pattern.compile("(?s)((?:\\s*" + hbn + "\\.print(?:ln)?\\(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"\\);)+)");
Matcher gme = lp.matcher(gen);
int oend = 0;
while (gme.find()) {
int mstart = gme.start();
int mend = gme.end();
是重要的一部分。我的匹配字符串(StackOverflow从每行中删除一个选项卡,但不会更改结果):
out.println("<!DOCTYPE html>");
out.println("<html lang=\"en\">");
out.println("<head>");
out.println("");
out.println("<meta charset=\"utf-8\">");
out.println("<title>Admin Theme 1.0</title>");
out.println("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">");
out.println("<meta name=\"description\" content=\"\">");
out.println("<meta name=\"author\" content=\"\">");
out.println("");
out.println("<!-- Le styles -->");
out.println("<link href=\"http://fonts.googleapis.com/css?family=Oxygen\" rel=\"stylesheet\" type=\"text/css\">");
out.println("<link href=\"assets/css/bootstrap.css\" rel=\"stylesheet\">");
out.println("<link href=\"assets/css/font-awesome.css\" rel=\"stylesheet\">");
out.println("<link href=\"assets/css/admin.css\" rel=\"stylesheet\">");
out.println("");
out.println("<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->");
out.println("<!--[if lt IE 9]>");
out.println("<script src=\"http://html5shim.googlecode.com/svn/trunk/html5.js\"></script>");
out.println("<![endif]-->");
out.println("");
out.println("</head>");
out.println("<body>");
out.println("");
out.println("<div class=\"masthead\">");
out.println("");
out.println("<div class=\"container\">");
out.println("");
out.println("<div class=\"masthead-top clearfix\">");
out.println("");
out.println("<ul class=\"nav nav-pills pull-right\">");
out.println("<li>");
out.println("<a href=\"#\"><i class=\"icon-globe\"></i> View Website</a>");
out.println("</li>");
out.println("<li class=\"dropdown\">");
out.println("<a class=\"dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\"><i class=\"icon-user\"></i> John Smith <b class=\"caret\"></b>");
out.println("</a>");
out.println("<ul class=\"dropdown-menu\">");
out.println("<li><a href=\"profile.html\">Your Profile</a></li>");
out.println("<li class=\"active\"><a href=\"form.html\">Account Settings</a></li>");
out.println("<li class=\"divider\"></li>");
out.println("<li><a href=\"\">Logout</a></li>");
out.println("</ul>");
out.println("</li>");
out.println("</ul>");
out.println("");
out.println("<h1><i class=\"icon-bookmark icon-large\"></i> Ecommerce Website Admin</h1>");
out.println("");
out.println("</div>");
out.println("");
out.println("<div class=\"navbar\">");
out.println("<div class=\"navbar-inner\">");
out.println("<div class=\"container\">");
out.println("");
out.println("<!-- .btn-navbar is used as the toggle for collapsed navbar content -->");
out.println("<a class=\"btn btn-navbar\" data-toggle=\"collapse\" data-target=\".nav-collapse\">");
out.println("<span class=\"icon-bar\"></span>");
out.println("<span class=\"icon-bar\"></span>");
out.println("<span class=\"icon-bar\"></span>");
out.println("</a>");
out.println("");
out.println("<div class=\"nav-collapse\">");
out.println("<ul class=\"nav\">");
out.println("<li>");
out.println("<a href=\"index.html\"><i class=\"icon-home\"></i> Dashboard</a>");
out.println("</li>");
out.println("<li class=\"dropdown active\">");
out.println("<a class=\"dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\"><i class=\"icon-sitemap\"></i> Website <b class=\"caret\"></b></a>");
out.println("<ul class=\"dropdown-menu\">");
out.println("<li><a href=\"listing.html\">Pages</a></li>");
out.println("<li><a href=\"listing.html\">Menus</a></li>");
out.println("</ul>");
out.println("</li>");
out.println("<li class=\"dropdown\">");
out.println("<a class=\"dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\"><i class=\"icon-shopping-cart\"></i> Store <b class=\"caret\"></b></a>");
out.println("<ul class=\"dropdown-menu\">");
out.println("<li><a href=\"listing.html\">Catalogue</a></li>");
out.println("<li><a href=\"orders.html\">Orders</a></li>");
out.println("<li><a href=\"listing.html\">Enquiries</a></li>");
out.println("</ul>");
out.println("</li>");
out.println("<li class=\"dropdown\">");
out.println("<a class=\"dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\"><i class=\"icon-signal\"></i> Reports <b class=\"caret\"></b></a>");
out.println("<ul class=\"dropdown-menu\">");
out.println("<li><a href=\"report.html\">Sales Reports</a></li>");
out.println("<li><a href=\"report.html\">Product Popularity</a></li>");
out.println("<li><a href=\"report.html\">Member Registrations</a></li>");
out.println("</ul>");
out.println("</li>");
out.println("<li class=\"dropdown\">");
out.println("<a class=\"dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\"><i class=\"icon-group\"></i> Members <b class=\"caret\"></b></a>");
out.println("<ul class=\"dropdown-menu\">");
out.println("<li><a href=\"listing.html\">Members</a></li>");
out.println("<li><a href=\"listing.html\">User Groups</a></li>");
out.println("<li><a href=\"listing.html\">Permissions</a></li>");
out.println("</ul>");
out.println("</li>");
out.println("<li class=\"dropdown\">");
out.println("<a class=\"dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\"><i class=\"icon-cogs\"></i> Settings <b class=\"caret\"></b></a>");
out.println("<ul class=\"dropdown-menu\">");
out.println("<li><a href=\"listing.html\">Payment Processors</a></li>");
out.println("<li><a href=\"listing.html\">Order Statuses</a></li>");
out.println("<li><a href=\"listing.html\">Shipping Methods</a></li>");
out.println("<li><a href=\"listing.html\">Emails</a></li>");
out.println("</ul>");
out.println("</li>");
out.println("</ul>");
out.println("<ul class=\"nav pull-right\">");
out.println("<li><a href=\"#\"><i class=\"icon-bullhorn\"></i> Alerts<span class=\"badge badge-info\">2</span></a></li>");
out.println("<li class=\"dropdown\">");
out.println("<a class=\"dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\"><i class=\"icon-info-sign\"></i> Help <b class=\"caret\"></b></a>");
out.println("<ul class=\"dropdown-menu\">");
out.println("<li><a href=\"content.html\">FAQ</a></li>");
out.println("<li class=\"active\"><a href=\"content.html\">User Guide</a></li>");
out.println("<li><a href=\"content.html\">Support</a></li>");
out.println("</ul>");
out.println("</li>");
out.println("</ul>");
out.println("</div>");
out.println("</div>");
out.println("</div>");
out.println("</div>");
out.println("");
out.println("</div>");
out.println("");
out.println("</div>");
out.println("");
out.println("<div class=\"secondary-masthead\">");
out.println("");
out.println("<div class=\"container\">");
out.println("");
out.println("<ul class=\"breadcrumb\">");
out.println("<li>");
out.println("<a href=\"#\">Admin</a> <span class=\"divider\">/</span>");
out.println("</li>");
out.println("<li>");
out.println("<a href=\"#\">Website</a> <span class=\"divider\">/</span>");
out.println("</li>");
out.println("<li class=\"active\">Form</li>");
out.println("</ul>");
out.println("");
out.println("</div>");
out.println("");
out.println("</div>");
out.println("");
out.println("<div class=\"main-area dashboard\">");
out.println("");
out.println("<div class=\"container\">");
out.println("");
out.println("<div class=\"alert alert-info\">");
out.println("<a class=\"close\" data-dismiss=\"alert\" href=\"#\">x</a>");
out.println("<h4 class=\"alert-heading\">Information</h4>");
out.println("This template shows how forms can be laid out for editing content.");
out.println("</div>");
out.println("");
out.println("<div class=\"alert alert-error\">");
out.println("<a class=\"close\" data-dismiss=\"alert\" href=\"#\">x</a>");
out.println("<h4 class=\"alert-heading\">Error</h4>");
out.println("Example of an error message alert.");
out.println("</div>");
out.println("");
out.println("<div class=\"alert alert-success\">");
out.println("<a class=\"close\" data-dismiss=\"alert\" href=\"#\">x</a>");
out.println("<h4 class=\"alert-heading\">Success</h4>");
out.println("Example of an success message alert.");
out.println("</div>");
out.println("");
out.println("<div class=\"alert alert-warning\">");
out.println("<a class=\"close\" data-dismiss=\"alert\" href=\"#\">x</a>");
out.println("<h4 class=\"alert-heading\">Warning</h4>");
out.println("Example of an warning message alert.");
out.println("</div>");
out.println("");
out.println("<div class=\"row\">");
out.println("");
out.println("<div class=\"span12\">");
out.println("");
out.println("<div class=\"slate\">");
out.println("");
out.println("<form class=\"form-inline\">");
out.println("<input type=\"text\" class=\"input-large\" placeholder=\"Keywords...\">");
out.println("<select>");
out.println("<option value=\"\"> - From Date - </option>");
out.println("</select>");
out.println("<select>");
out.println("<option value=\"\"> - To Date - </option>");
out.println("</select>");
out.println("<select>");
out.println("<option value=\"\"> - Filter - </option>");
out.println("</select>");
out.println("<button type=\"submit\" class=\"btn btn-primary\">Filter</button>");
out.println("</form>");
out.println("");
out.println("</div>");
out.println("");
out.println("</div>");
out.println("");
out.println("</div>");
out.println("");
out.println("<div class=\"row\">");
out.println("");
out.println("<div class=\"span12 listing-buttons\">");
out.println("");
out.println("<button class=\"btn btn-info\">Action</button>");
out.println("");
out.println("<button class=\"btn btn-success\">Action</button>");
out.println("");
out.println("<button class=\"btn btn-primary\">Add New Order</button>");
out.println("");
out.println("</div>");
out.println("");
out.println("<div class=\"span12\">");
out.println("");
out.println("<div class=\"slate\">");
out.println("");
out.println("<div class=\"page-header\">");
out.println("<h2>Form Title</h2>");
out.println("</div>");
out.println("");
out.println("<form class=\"form-horizontal\">");
out.println("<fieldset>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\" for=\"focusedInput\">Focused input</label>");
out.println("<div class=\"controls\">");
out.println("<input class=\"input-xlarge focused\" id=\"focusedInput\" type=\"text\" value=\"This is focused…\">");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\">Uneditable input</label>");
out.println("<div class=\"controls\">");
out.println("<span class=\"input-xlarge uneditable-input\">Some value here</span>");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\" for=\"disabledInput\">Disabled input</label>");
out.println("<div class=\"controls\">");
out.println("<input class=\"input-xlarge disabled\" id=\"disabledInput\" type=\"text\" placeholder=\"Disabled input here…\" disabled>");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\" for=\"optionsCheckbox2\">Disabled checkbox</label>");
out.println("<div class=\"controls\">");
out.println("<label class=\"checkbox\">");
out.println("<input type=\"checkbox\" id=\"optionsCheckbox2\" value=\"option1\" disabled>");
out.println("This is a disabled checkbox");
out.println("</label>");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group warning\">");
out.println("<label class=\"control-label\" for=\"inputWarning\">Input with warning</label>");
out.println("<div class=\"controls\">");
out.println("<input type=\"text\" id=\"inputWarning\">");
out.println("<span class=\"help-inline\">Something may have gone wrong</span>");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group error\">");
out.println("<label class=\"control-label\" for=\"inputError\">Input with error</label>");
out.println("<div class=\"controls\">");
out.println("<input type=\"text\" id=\"inputError\">");
out.println("<span class=\"help-inline\">Please correct the error</span>");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group success\">");
out.println("<label class=\"control-label\" for=\"inputSuccess\">Input with success</label>");
out.println("<div class=\"controls\">");
out.println("<input type=\"text\" id=\"inputSuccess\">");
out.println("<span class=\"help-inline\">Woohoo!</span>");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group success\">");
out.println("<label class=\"control-label\" for=\"selectError\">Select with success</label>");
out.println("<div class=\"controls\">");
out.println("<select id=\"selectError\">");
out.println("<option>1</option>");
out.println("<option>2</option>");
out.println("<option>3</option>");
out.println("<option>4</option>");
out.println("<option>5</option>");
out.println("</select>");
out.println("<span class=\"help-inline\">Woohoo!</span>");
out.println("</div>");
out.println("</div>");
out.println("</fieldset>");
out.println("</form>");
out.println("");
out.println("</div>");
out.println("");
out.println("</div>");
out.println("");
out.println("<div class=\"span6\">");
out.println("");
out.println("<div class=\"slate\">");
out.println("");
out.println("<div class=\"page-header\">");
out.println("<h2>Form Title</h2>");
out.println("</div>");
out.println("");
out.println("<form class=\"form-horizontal\">");
out.println("<fieldset>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\" for=\"input01\">Text input</label>");
out.println("<div class=\"controls\">");
out.println("<input type=\"text\" class=\"input-xlarge\" id=\"input01\">");
out.println("<p class=\"help-block\">In addition to freeform text, any HTML5 text-based input appears like so.</p>");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\" for=\"optionsCheckbox\">Checkbox</label>");
out.println("<div class=\"controls\">");
out.println("<label class=\"checkbox\">");
out.println("<input type=\"checkbox\" id=\"optionsCheckbox\" value=\"option1\">");
out.println("Option one is this and that—be sure to include why it's great");
out.println("</label>");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\" for=\"select01\">Select list</label>");
out.println("<div class=\"controls\">");
out.println("<select id=\"select01\">");
out.println("<option>something</option>");
out.println("<option>2</option>");
out.println("<option>3</option>");
out.println("<option>4</option>");
out.println("<option>5</option>");
out.println("</select>");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\" for=\"multiSelect\">Multicon-select</label>");
out.println("<div class=\"controls\">");
out.println("<select multiple=\"multiple\" id=\"multiSelect\">");
out.println("<option>1</option>");
out.println("<option>2</option>");
out.println("<option>3</option>");
out.println("<option>4</option>");
out.println("<option>5</option>");
out.println("</select>");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\" for=\"fileInput\">File input</label>");
out.println("<div class=\"controls\">");
out.println("<input class=\"input-file\" id=\"fileInput\" type=\"file\">");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\" for=\"textarea\">Textarea</label>");
out.println("<div class=\"controls\">");
out.println("<textarea class=\"input-xlarge\" id=\"textarea\" rows=\"3\"></textarea>");
out.println("</div>");
out.println("</div>");
out.println("</fieldset>");
out.println("</form>");
out.println("");
out.println("</div>");
out.println("");
out.println("</div>");
out.println("");
out.println("<div class=\"span6\">");
out.println("");
out.println("<div class=\"slate\">");
out.println("");
out.println("<div class=\"page-header\">");
out.println("<h2>Form Title</h2>");
out.println("</div>");
out.println("");
out.println("<form class=\"form-horizontal\">");
out.println("<fieldset>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\" for=\"input01\">Text input</label>");
out.println("<div class=\"controls\">");
out.println("<input type=\"text\" class=\"input-xlarge\" id=\"input01\">");
out.println("<p class=\"help-block\">In addition to freeform text, any HTML5 text-based input appears like so.</p>");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\" for=\"optionsCheckbox\">Checkbox</label>");
out.println("<div class=\"controls\">");
out.println("<label class=\"checkbox\">");
out.println("<input type=\"checkbox\" id=\"optionsCheckbox\" value=\"option1\">");
out.println("Option one is this and that—be sure to include why it's great");
out.println("</label>");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\" for=\"select01\">Select list</label>");
out.println("<div class=\"controls\">");
out.println("<select id=\"select01\">");
out.println("<option>something</option>");
out.println("<option>2</option>");
out.println("<option>3</option>");
out.println("<option>4</option>");
out.println("<option>5</option>");
out.println("</select>");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\" for=\"multiSelect\">Multicon-select</label>");
out.println("<div class=\"controls\">");
out.println("<select multiple=\"multiple\" id=\"multiSelect\">");
out.println("<option>1</option>");
out.println("<option>2</option>");
out.println("<option>3</option>");
out.println("<option>4</option>");
out.println("<option>5</option>");
out.println("</select>");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\" for=\"fileInput\">File input</label>");
out.println("<div class=\"controls\">");
out.println("<input class=\"input-file\" id=\"fileInput\" type=\"file\">");
out.println("</div>");
out.println("</div>");
out.println("<div class=\"control-group\">");
out.println("<label class=\"control-label\" for=\"textarea\">Textarea</label>");
out.println("<div class=\"controls\">");
out.println("<textarea class=\"input-xlarge\" id=\"textarea\" rows=\"3\"></textarea>");
out.println("</div>");
out.println("</div>");
out.println("</fieldset>");
out.println("</form>");
out.println("");
out.println("</div>");
out.println("");
out.println("</div>");
out.println("");
out.println("<div class=\"span12 listing-buttons\">");
out.println("");
out.println("<button class=\"btn btn-info\">Action</button>");
out.println("");
out.println("<button class=\"btn btn-success\">Action</button>");
out.println("");
out.println("<button class=\"btn btn-primary\">Add New Item</button>");
out.println("");
out.println("</div>");
out.println("");
out.println("</div>");
out.println("");
out.println("<div class=\"row\">");
out.println("");
out.println("<div class=\"span12 footer\">");
out.println("");
out.println("<p>© Website Name 2012</p>");
out.println("");
out.println("</div>");
out.println("");
out.println("</div>");
out.println("");
out.println("</div>");
out.println("");
out.println("</div>");
out.println("");
out.println("<!-- Le javascript");
out.println("================================================== -->");
out.println("<!-- Placed at the end of the document so the pages load faster -->");
out.println("<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js\"></script>");
out.println("<script src=\"assets/js/bootstrap.js\"></script>");
out.println("<script src=\"assets/js/excanvas.min.js\"></script>");
out.println("<script src=\"assets/js/jquery.flot.min.js\"></script>");
out.println("<script src=\"assets/js/jquery.flot.resize.js\"></script>");
out.println("<script type=\"text/javascript\">");
out.println("$(function () {");
out.println("var d1 = [];");
out.println("d1.push([0, 20]);");
out.println("d1.push([1, 16]);");
out.println("d1.push([2, 17]);");
out.println("d1.push([3, 25]);");
out.println("d1.push([4, 51]);");
out.println("d1.push([5, 57]);");
out.println("d1.push([6, 46]);");
out.println("d1.push([7, 36]);");
out.println("d1.push([8, 27]);");
out.println("d1.push([9, 36]);");
out.println("d1.push([10, 38]);");
out.println("d1.push([11, 41]);");
out.println("d1.push([12, 45]);");
out.println("d1.push([13, 48]);");
out.println("d1.push([14, 40]);");
out.println("d1.push([15, 36]);");
out.println("d1.push([16, 34]);");
out.println("");
out.println("$.plot($(\"#placeholder\"), [ d1 ], { grid: { backgroundColor: 'white', color: '#999', borderWidth: 1, borderColor: '#DDD' }, colors: [\"#f89406\"], series: { lines: { show: true, fill: true, fillColor: \"rgba(248, 148, 6, 0.5)\" } } });");
out.println("});");
out.println("</script>");
out.println("");
out.println("</body>");
out.println("</html>");
只有一个匹配,整个文本(如果你没有注意到,这是匹配Java,那里可能还有其他代码)。当我第一次调用gme.find()时,它就会挂起。我让它在100%CPU下运行几分钟,它从未解决,所以我认为它是无限循环的。我可能做错了什么?我把所有这些都输入到Regex101中,它完美地运行了13839步。它是JVM Regex引擎中的错误吗?如果重要的话我会使用OpenJDK。