diff --git a/settings/admin.php b/settings/admin.php
index 533b6152492c6c01cc0fb7827592ae5bec7903b9..551608b5d25b631858e98eb2e564db83acad2c7b 100644
--- a/settings/admin.php
+++ b/settings/admin.php
@@ -197,8 +197,8 @@ if (\OC::$server->getLockingProvider() instanceof NoopLockingProvider) {
 }
 
 $formsMap = array_map(function ($form) {
-	if (preg_match('%(<h2[^>]*>.*?</h2>)%i', $form, $regs)) {
-		$sectionName = str_replace('<h2>', '', $regs[0]);
+	if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
+		$sectionName = str_replace('<h2'.$regs['class'].'>', '', $regs[0]);
 		$sectionName = str_replace('</h2>', '', $sectionName);
 		$anchor = strtolower($sectionName);
 		$anchor = str_replace(' ', '-', $anchor);
diff --git a/settings/personal.php b/settings/personal.php
index f4409e633cf316eb9d0f2c7f705b84333f45d54c..8823102e01a21ce3ecd22d3bd35dff2040ff3fd1 100644
--- a/settings/personal.php
+++ b/settings/personal.php
@@ -137,8 +137,8 @@ $formsAndMore[]= ['anchor' => 'passwordform', 'section-name' => $l->t('Personal
 $forms=OC_App::getForms('personal');
 
 $formsMap = array_map(function($form){
-	if (preg_match('%(<h2[^>]*>.*?</h2>)%i', $form, $regs)) {
-		$sectionName = str_replace('<h2>', '', $regs[0]);
+	if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
+		$sectionName = str_replace('<h2'.$regs['class'].'>', '', $regs[0]);
 		$sectionName = str_replace('</h2>', '', $sectionName);
 		$anchor = strtolower($sectionName);
 		$anchor = str_replace(' ', '-', $anchor);