import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "bugid.*\\n(.*)";
final String string = "bugid = 461 \n"
+ "comment#461 = drop-cap position for hanging, jutting, etc \n"
+ "bugid = 466 \n"
+ "comment#466 = Positioning printouts on the page \n"
+ "bugid = 480 \n"
+ "comment#480 = Being able to *switch* items in the Distribute/Align menu \n"
+ "bugid = 492 \n"
+ "comment#492 = Footnotes which stay on the same page as the associated word \n"
+ "bugid = 498 \n"
+ "comment#498 = Typography Preference Settings as part of Paragraph Styles \n"
+ "bugid = 502 \n"
+ "comment#502 = Multiselection in items Overview \n"
+ "bugid = 504 \n"
+ "comment#504 = We need more accuray object selection \n"
+ "bugid = 505 \n"
+ "comment#505 = Object sellection with Ctrl \n"
+ "bugid = 533 \n"
+ "comment#533 = move objects in the object-tree \n"
+ "bugid = 555 \n"
+ "comment#555 = rotating objects without rotate-cursor ? \n"
+ "bugid = 575 \n"
+ "comment#575 = (in general multiple application of properties) \n"
+ "bugid = 577 \n"
+ "comment#577 = Paragraph Styles -> Kerning and language options missing \n"
+ "bugid = 579 \n"
+ "comment#579 = right-click paragraph, save as paragraph style \n"
+ "bugid = 689 \n"
+ "comment#689 = basepoint of lines cannot be set to the middle or diagonal one \n"
+ "bugid = 835 \n"
+ "comment#835 = Measurement attachment to the guides and frames \n"
+ "bugid = 889 \n"
+ "comment#889 = inverse bezier tool handling \n"
+ "bugid = 950 \n"
+ "comment#950 = The search and replace dialogue should not be modal because the way it is now you cannot cut and paste into it. \n"
+ "bugid = 990 \n"
+ "comment#990 = Mail-Merge \n"
+ "bugid = 1008 \n"
+ "comment#1008 = ? \n"
+ "bugid = 1032 \n"
+ "comment#1032 = Request: PDF Bookmarks at arbritrary locations within text frames. \n"
+ "bugid = 1034 \n"
+ "comment#1034 = Edit Paste disabled after copy from another program, but Control V works \n"
+ "bugid = 1037 \n"
+ "comment#1037 = GetTextLength returns 0 for non-empty frame \n"
+ "bugid = 1069 \n"
+ "comment#1069 = Auto-adjust size of text box to the text \n"
+ "bugid = 1085 \n"
+ "comment#1085 = Better text on path control \n"
+ "bugid = 1086 \n"
+ "comment#1086 = Lines styles with two or more parallel lines \n"
+ "bugid = 1094 \n"
+ "comment#1094 = Importing multipage PDFs must give options for importing a selection of pages see also 1352 (dup) \n"
+ "bugid = 1118 \n"
+ "comment#1118 = Give instant access to Style editor from within the Properties palette>Text \n"
+ "bugid = 1212 \n"
+ "comment#1212 = styles for drop caps \n"
+ "bugid = 1321 \n"
+ "comment#1321 = Individual DPI settings \n"
+ "bugid = 1398 \n"
+ "comment#1398 = Improve memory efficiency of raster image export \n"
+ "bugid = 1406 \n"
+ "comment#1406 = Add text metrics to scripter \n"
+ "bugid = 1410 \n"
+ "comment#1410 = Allow automatic text frames after document has been started \n"
+ "bugid = 1423 \n"
+ "comment#1423 = Single key-stroke to kern letters... \n"
+ "bugid = 1462 \n"
+ "comment#1462 = Lines (borders) on frames are drawn from the center of the edge to the outside \n"
+ "bugid = 1463 \n"
+ "comment#1463 = Add pdf export \"templates\" \n"
+ "bugid = 1474 \n"
+ "comment#1474 = RTF Import \n"
+ "bugid = 1475 \n"
+ "comment#1475 = Bad hyphenating implementation \n"
+ "bugid = 1518 \n"
+ "comment#1518 = PrefsTable breaks if indexing is started from (1,0) \n"
+ "bugid = 1540 \n"
+ "comment#1540 = Issue with stylesheet and emphasis like italic or bold fonts \n"
+ "bugid = 1569 \n"
+ "comment#1569 = regression from 1.2 \n"
+ "bugid = 1592 \n"
+ "comment#1592 = New textframes not linkable to \"Autoframes\" \n"
+ "bugid = 1598 \n"
+ "comment#1598 = - assigned Missing preference to text importer \n"
+ "bugid = 1622 \n"
+ "comment#1622 = Splitting the import menu \n"
+ "bugid = 1627 \n"
+ "comment#1627 = improvement for handling changes in images on disc \n"
+ "bugid = 1629 \n"
+ "comment#1629 = A need to run menu items from the scriptor for automation purposes \n"
+ "bugid = 1630 \n"
+ "comment#1630 = A macro recorder to build a script automatically from users actions. \n"
+ "bugid = 1663 \n"
+ "comment#1663 = ability to assign shortcut keys to the running of a script \n"
+ "bugid = 1671 \n"
+ "comment#1671 = - needs testing \n"
+ "bugid = 1678 \n"
+ "comment#1678 = Search in Picture Management should search user specified directory list, pick up all matching images in dir. \n"
+ "bugid = 2264 \n"
+ "comment#2264 = - Support more PDF/X-x versions \n"
+ "bugid = 2460 \n"
+ "comment#2460 = - Support JDF";
final String subst = "\\1\\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
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