_{}|]/'; $replacement = static function ( $matches ) { return '\\' . $matches[0]; }; return \preg_replace_callback( $pattern, $replacement, $text ); } /** * Escapes URLs in markdown. * * @param string $url The markdown URL to escape. * * @return string The escaped markdown URL. */ public function escape_markdown_url( $url ) { $escaped_url = \str_replace( [ ' ', '(', ')', '\\' ], [ '%20', '%28', '%29', '%5C' ], $url ); return $escaped_url; } }