import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(^\\w.*\\n\\n)+(^(##.*\\n)+)";
final String string = "tab_bar_edge top\n\n"
+ "## Which edge to show the tab bar on, top or bottom\n\n"
+ "tab_bar_margin_width 0.0\n\n"
+ "## The margin to the left and right of the tab bar (in pts)\n\n"
+ "tab_bar_margin_height 0.0 0.0\n\n"
+ "## The margin above and below the tab bar (in pts). The first number\n"
+ "## is the margin between the edge of the OS Window and the tab bar and\n"
+ "## the second number is the margin between the tab bar and the\n"
+ "## contents of the current tab.\n\n"
+ "tab_bar_style fade\n\n"
+ "## The tab bar style, can be one of:\n"
+ "## \n"
+ "## fade\n"
+ "## Each tab's edges fade into the background color (see tab_fade)\n"
+ "## slant\n"
+ "## Tabs look like the tabs in a physical file\n"
+ "## separator\n"
+ "## Tabs are separated by a configurable separator (see tab_separator)\n"
+ "## powerline\n"
+ "## Tabs are shown as a continuous line with \"fancy\" separators\n"
+ "## (see tab_powerline_style)\n"
+ "## custom\n"
+ "## A user-supplied Python function called draw_tab is loaded from the file\n"
+ "## tab_bar.py in the kitty config directory. For examples of how to\n"
+ "## write such a function, see the functions named draw_tab_with_* in\n"
+ "## kitty's source code: kitty/tab_bar.py. See also\n"
+ "## this discussion https://github.com/kovidgoyal/kitty/discussions/4447\n"
+ "## for examples from kitty users.\n"
+ "## hidden\n"
+ "## The tab bar is hidden. If you use this, you might want to create a\n"
+ "## mapping for the https://sw.kovidgoyal.net/kitty/actions/#select-tab\n"
+ "## action which presents you with a list of tabs and allows for easy\n"
+ "## switching to a tab.\n\n"
+ "tab_bar_align left\n\n"
+ "## The horizontal alignment of the tab bar, can be one of: left,\n"
+ "## center, or right.\n\n"
+ "tab_bar_min_tabs 2\n\n"
+ "## The minimum number of tabs that must exist before the tab bar is\n"
+ "## shown\n\n"
+ "tab_switch_strategy previous\n\n"
+ "## The algorithm to use when switching to a tab when the current tab\n"
+ "## is closed. The default of previous will switch to the last used\n"
+ "## tab. A value of left will switch to the tab to the left of the\n"
+ "## closed tab. A value of right will switch to the tab to the right of\n"
+ "## the closed tab. A value of last will switch to the right-most tab.\n\n"
+ "tab_fade 0.25 0.5 0.75 1\n\n"
+ "## Control how each tab fades into the background when using fade for\n"
+ "## the tab_bar_style. Each number is an alpha (between zero and one)\n"
+ "## that controls how much the corresponding cell fades into the\n"
+ "## background, with zero being no fade and one being full fade. You\n"
+ "## can change the number of cells used by adding/removing entries to\n"
+ "## this list.\n\n"
+ "tab_separator \" ┇\"\n\n"
+ "## The separator between tabs in the tab bar when using separator as\n"
+ "## the tab_bar_style.\n\n"
+ "tab_powerline_style angled\n\n"
+ "## The powerline separator style between tabs in the tab bar when\n"
+ "## using powerline as the tab_bar_style, can be one of: angled,\n"
+ "## slanted, or round.\n\n"
+ "tab_activity_symbol none\n\n"
+ "## Some text or a unicode symbol to show on the tab if a window in the\n"
+ "## tab that does not have focus has some activity. If you want to use\n"
+ "## leading or trailing spaces surround the text with quotes. See\n"
+ "## tab_title_template for how this is rendered.\n\n"
+ "tab_title_template \"{fmt.fg.red}{bell_symbol}{activity_symbol}{fmt.fg.tab}{title}\"\n\n"
+ "## A template to render the tab title. The default just renders the\n"
+ "## title with optional symbols for bell and activity. If you wish to\n"
+ "## include the tab-index as well, use something like: {index}:\n"
+ "## {title}. Useful if you have shortcuts mapped for goto_tab N. If you\n"
+ "## prefer to see the index as a superscript, use {sup.index}. In\n"
+ "## addition you can use {layout_name} for the current layout name,\n"
+ "## {num_windows} for the number of windows in the tab and\n"
+ "## {num_window_groups} for the number of window groups (not counting\n"
+ "## overlay windows) in the tab. Note that formatting is done by\n"
+ "## Python's string formatting machinery, so you can use, for instance,\n"
+ "## {layout_name[:2].upper()} to show only the first two letters of the\n"
+ "## layout name, upper-cased. If you want to style the text, you can\n"
+ "## use styling directives, for example:\n"
+ "## {fmt.fg.red}red{fmt.fg.tab}normal{fmt.bg._00FF00}green\n"
+ "## bg{fmt.bg.tab}. Similarly, for bold and italic:\n"
+ "## {fmt.bold}bold{fmt.nobold}normal{fmt.italic}italic{fmt.noitalic}.\n"
+ "## Note that for backward compatibility, if {bell_symbol} or\n"
+ "## {activity_symbol} are not present in the template, they are\n"
+ "## prepended to it.\n\n"
+ "active_tab_title_template none\n\n"
+ "## Template to use for active tabs, if not specified falls back to\n"
+ "## tab_title_template.\n\n"
+ "xxxxxactive_tab_foreground #000\n"
+ "active_tab_background #eee\n"
+ "active_tab_font_style bold-italic\n"
+ "inactive_tab_foreground #444\n"
+ "yyyyinactive_tab_background #999\n"
+ "zzzzzinactive_tab_font_style normal\n\n"
+ "## Tab bar colors and styles\n\n"
+ "tab_bar_background none\n\n"
+ "## Background color for the tab bar. Defaults to using the terminal\n"
+ "## background color.\n\n"
+ "tab_bar_margin_color none\n\n"
+ "## Color for the tab bar margin area. Defaults to using the terminal\n"
+ "## background color.\n\n";
final String subst = "$2\\n$1";
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