The current OpenJDK 26 is strategically important and not only brings exciting innovations but also eliminates legacy issues ...
This is now available natively as RegExp.escape(). You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class.