Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://download.oracle.com/javase/6/docs/api/index.html?java/util/regex/Pattern.html" rel="nofollow">Pattern</a> has a <code>String quote(String)</code> function that will help you for the first string and <a href="http://download.oracle.com/javase/6/docs/api/index.html?java/util/regex/Matcher.html" rel="nofollow">Matcher</a> has <code>String quoteReplacement(String)</code> for the second:</p> <pre><code>path = path.replaceFirst(java.util.regex.Pattern.quote("$SERVER"), java.util.regex.Matcher.quoteReplacement(System.getProperty("user.dir"))); </code></pre> <p>edit: the reason you have to escape anything is because the second string has the semantics of <a href="http://download.oracle.com/javase/6/docs/api/java/util/regex/Matcher.html#appendReplacement%28java.lang.StringBuffer,%20java.lang.String%29" rel="nofollow">Matcher.appendReplacement</a> which treats backslashes and dollars as escape next char and insert captured group resp. </p> <p>from the doc:</p> <blockquote> <p>Note that backslashes () and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string. Dollar signs may be treated as references to captured subsequences as described above, and backslashes are used to escape literal characters in the replacement string.</p> </blockquote> <p>a more obvious solution is (be careful of the needed escaped with that backslash)</p> <pre><code> path = path.replaceFirst("\\$SERVER", System.getProperty("user.dir").replaceAll("\\\\","\\\\\\\\")); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload