title: Java regex: Replace all characters with `+` except instances of a given string
body: <p>I have the following problem which states</p>
  
  <blockquote>
    <p>Replace all characters in a string with <code>+</code> symbol except instances of the given string in the method</p>
  </blockquote>
  
  <p>so for example if the string given was <code>abc123efg</code> and they want me to replace every character except every instance of <code>123</code> then it would become <code>+++123+++</code>.</p>
  
  <p>I figured a regular expression is probably the best for this and I came up with this.</p>
  
  <pre><code>str.replaceAll("[^str]","+") 
  </code></pre>
  
  <p>where str is a variable, but its not letting me use the method without putting it in quotations. If I just want to replace the variable string str how can I do that? I ran it with the string manually typed and it worked on the method, but can I just input a variable?</p>
  
  <p>as of right now I believe its looking for the string "str" and not the variable string.</p>
  
  <p>Here is the output its right for so many cases except for two :(</p>
  
  <p><a href="https://i.stack.imgur.com/Ic9Ni.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Ic9Ni.png" alt="enter image description here"></a></p>
  
  <p>List of open test cases:</p>
  
  <pre><code>plusOut("12xy34", "xy") → "++xy++"
  plusOut("12xy34", "1") → "1+++++"
  plusOut("12xy34xyabcxy", "xy") → "++xy++xy+++xy"
  plusOut("abXYabcXYZ", "ab") → "ab++ab++++"
  plusOut("abXYabcXYZ", "abc") → "++++abc+++"
  plusOut("abXYabcXYZ", "XY") → "++XY+++XY+"
  plusOut("abXYxyzXYZ", "XYZ") → "+++++++XYZ"
  plusOut("--++ab", "++") → "++++++"
  plusOut("aaxxxxbb", "xx") → "++xxxx++"
  plusOut("123123", "3") → "++3++3"
  </code></pre>