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