Is there a library or any simple way to convert a string and make sure it is compatible as a regular expression to search and replace on another string. Therefore, if the string is "$ money", it is converted to "\ $ money". I tried using StringEscapeUtil.escape, but it does not work with characters like $.
You can use Pattern.quote("$money") .
Pattern.quote("$money")
Prepare \\Q before the line and \\E at the end:
\\Q
\\E
"\\Q$money\\E"
This tells the regex engine that the line between \Q and \E should be interpreted verbatim, ignoring any metacharacters it may contain.
\Q
\E
Source: https://habr.com/ru/post/1487381/More articles:Does AJAX not call PHP? - jqueryHow to check if a device is registered in MDM - iosclosing unused handle RODBC - rHow to free term erlang - cSharedPreferences overwrites another value - androidNaive Bayes model in R on a sparse matrix - rCKEditor - ruby-on-railsConverting Active Record to a hash array - ruby-on-railsCalculate Percentage of the total number of records with scope and display virtual attributes (Rails / Active Record) - ruby | fooobar.comDoes posix_fallocate work with files opened with added mode? - c ++All Articles