How to replace String $1with Java? I tried this, but this does not replace it:
$1
System.out.println(someHTMLCodeAsString.replaceAll("$1", "REPLACED"));
The value of $ is interpreted as a regular expression, and not as a character (this means "end of line"). TrySystem.out.println(someHTMLCodeAsString.replaceAll("\\$1", "REPLACED"));
System.out.println(someHTMLCodeAsString.replaceAll("\\$1", "REPLACED"));
to try
System.out.println(someHTMLCodeAsString.replace("$1", "REPLACED"));
Java API: " , () ($) , , , . Matcher.replaceAll. quoteReplacement (java.lang.String) , .
You have a bit and bits of answer. Peter Laurie is right. You need to avoid $ with a regular expression excerpt rather than an escape string, so double \.
System.out.println (someHTMLCodeAsString.replaceAll ("\\ $ 1", "REPLACED"));
Or, let the regex library process it for you:
someHTMLCodeAsString.replaceAll(Pattern.quote("$1"), "REPLACED")
You can simply use this method:
someHTMLCodeAsString.replaceAll("\\$1", "REPLACED").
Just replace all "$" with "REPLACED"!
Source: https://habr.com/ru/post/1782200/More articles:Referencing objects programmatically configured with Interface Builder - designКак отправить почту в php в запланированное время? - phphttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1782197/converting-non-main-runloop-tasks-to-gcd&usg=ALkJrhhZb5-z3qeE8R9V35LgJ0f0n-Y7fwsecurity issues - securityHow to get image from this BBC channel using Python and Universal Parser - pythonRedirecting when catching an exception in a method in a model - ruby-on-railsConnect to mysql - pythonHow to deactivate a specific version of a gem? - ruby-on-railsWhy #define INVALID_VALUE -999; give syntax error when using? - cThe difference between the "and" characters in jQuery - javascriptAll Articles