0

Is there a way in Java, when you use a RegEx look-behind to look for more than 1 character behind? I have this:

return str.replaceAll(".(?<!" + word + ")", "+");

With what I can replace the "?" in the RegEx to get the lookbehind for more than 1 char? Say 2 or 3 chars.

Dimitar
  • 4,402
  • 4
  • 31
  • 47
  • The regex you have should work, the "?" in this case doesn't mean "one character" – morgano Mar 24 '15 at 10:35
  • I've just noticed you have a dot before your negative-look-behind, What are you trying to do? – morgano Mar 24 '15 at 10:35
  • @morgano isn't ? for 0 or 1 char? Or I am wrong? I try to leave it unchanged so like: `Input str = "12xy45" word = "xy" Output "++xy++"` – Dimitar Mar 24 '15 at 11:56

0 Answers0