import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?m)^(\\h*)maxlength:(?:\\R\\1(?!\\h*maxlength_js_enforce:)(\\h+).*)*$(?!\\R\\1\\h)";
final String string = "uuid: e3737897-ae40-4771-8aff-33d2fe76eeee\n"
+ "langcode: de\n"
+ "status: true\n"
+ "dependencies:\n"
+ " config:\n"
+ " - config_pages.type.chatbot\n"
+ " - field.field.config_pages.chatbot.field_2click_solution_label\n"
+ " - field.field.config_pages.chatbot.field_2click_solution_logo\n"
+ " - field.field.config_pages.chatbot.field_2click_solution_popup_text\n"
+ " - field.field.config_pages.chatbot.field_title_div\n"
+ " - field.field.config_pages.chatbot.field_url\n"
+ " module:\n"
+ " - field_group\n"
+ " - field_states_ui\n"
+ " - file\n"
+ " - link\n"
+ " - link_field_tweak\n"
+ " - maxlength\n"
+ " - text\n"
+ "third_party_settings:\n"
+ " field_group:\n"
+ " group_struktur_definitionen:\n"
+ " children:\n"
+ " - group_tab_settings\n"
+ " - group__tab_policy\n"
+ " label: 'Chatbot Einstellungen'\n"
+ " region: content\n"
+ " parent_name: ''\n"
+ " weight: 1\n"
+ " format_type: tabs\n"
+ " format_settings:\n"
+ " classes: ''\n"
+ " show_empty_fields: false\n"
+ " id: ''\n"
+ " direction: horizontal\n"
+ " width_breakpoint: 640\n"
+ " group_tab_settings:\n"
+ " children:\n"
+ " - field_url\n"
+ " - field_2click_solution_logo\n"
+ " - field_title_div\n"
+ " label: Einstellungen\n"
+ " region: content\n"
+ " parent_name: group_struktur_definitionen\n"
+ " weight: 20\n"
+ " format_type: tab\n"
+ " format_settings:\n"
+ " classes: ''\n"
+ " show_empty_fields: false\n"
+ " id: ''\n"
+ " formatter: closed\n"
+ " description: ''\n"
+ " required_fields: true\n"
+ " group__tab_policy:\n"
+ " children:\n"
+ " - field_2click_solution_label\n"
+ " - field_2click_solution_popup_text\n"
+ " label: Datenschutzhinweis\n"
+ " region: content\n"
+ " parent_name: group_struktur_definitionen\n"
+ " weight: 21\n"
+ " format_type: tab\n"
+ " format_settings:\n"
+ " classes: ''\n"
+ " show_empty_fields: false\n"
+ " id: ''\n"
+ " formatter: closed\n"
+ " description: ''\n"
+ " required_fields: true\n"
+ "id: config_pages.chatbot.default\n"
+ "targetEntityType: config_pages\n"
+ "bundle: chatbot\n"
+ "mode: default\n"
+ "content:\n"
+ " field_2click_solution_label:\n"
+ " type: string_textfield\n"
+ " weight: 22\n"
+ " region: content\n"
+ " settings:\n"
+ " size: 60\n"
+ " placeholder: ''\n"
+ " third_party_settings:\n"
+ " field_states_ui:\n"
+ " form:\n"
+ " type: ''\n"
+ " list: ''\n"
+ " add: Hinzufügen\n"
+ " maxlength:\n"
+ " maxlength_js: 60\n"
+ " maxlength_js_label: 'Inhalt auf @limit Zeichen begrenzt, verbleibend: <strong>@remaining</strong><br><br>'\n"
+ " field_2click_solution_logo:\n"
+ " type: file_generic\n"
+ " weight: 22\n"
+ " region: content\n"
+ " settings:\n"
+ " progress_indicator: throbber\n"
+ " third_party_settings: { }\n"
+ " field_2click_solution_popup_text:\n"
+ " type: text_textarea\n"
+ " weight: 23\n"
+ " region: content\n"
+ " settings:\n"
+ " rows: 5\n"
+ " placeholder: ''\n"
+ " third_party_settings:\n"
+ " field_states_ui:\n"
+ " form:\n"
+ " type: ''\n"
+ " list: ''\n"
+ " maxlength:\n"
+ " maxlength_js: null\n"
+ " maxlength_js_label: 'Inhalt auf @limit Zeichen begrenzt, verbleibend: <strong>@remaining</strong>'\n"
+ " maxlength_js_enforce: true\n"
+ " maxlength_js_truncate_html: false\n"
+ " field_title_div:\n"
+ " type: string_textfield\n"
+ " weight: 23\n"
+ " region: content\n"
+ " settings:\n"
+ " size: 60\n"
+ " placeholder: ''\n"
+ " third_party_settings: { }\n"
+ " field_url:\n"
+ " type: link_default\n"
+ " weight: 21\n"
+ " region: content\n"
+ " settings:\n"
+ " placeholder_url: 'URL zu einer JavaScript Datei'\n"
+ " placeholder_title: ''\n"
+ " third_party_settings:\n"
+ " field_states_ui:\n"
+ " form:\n"
+ " type: ''\n"
+ " list: ''\n"
+ " add: Hinzufügen\n"
+ " link_field_tweak:\n"
+ " uri_part_custom_help: false\n"
+ " uri_part_custom_help_text: ''\n"
+ " maxlength:\n"
+ " maxlength_js: null\n"
+ " maxlength_js_label: 'Inhalt auf @limit Zeichen begrenzt, verbleibend: <strong>@remaining</strong>'\n"
+ "hidden:\n"
+ " label: true\n"
+ " path: true\n";
final String subst = "$0\\n$1$2maxlength_js_enforce: true";
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