Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

2 of 4
added 41 characters in body
Krunal
  • 79.9k
  • 49
  • 255
  • 268

Java: String.replaceAll(regex, replacement);

I’ve a string of comma separated user-ids and I want to eliminate/remove specific user-id from a string.

I’ve following possibilities of string and expected result

int elimiate_user_id = 11
String css1 = "11,22,33,44,55" 
String css2 = "22,33,11,44,55" 
String css3 = "22,33,44,55,11" 
//Expected result in all cases, after replacement, should be: "22,33,44,55"

I tried following:

String result = css#.replaceAll("," + elimiate_user_id, ""); // # = 1 or 2 or 3
result = css#.replaceAll(elimiate_user_id + "," , "");

This logic fails in case of css3.

Pl. suggest me proper solution of this issue.
Note: I'm working with Java 7

I checked around following ques, but could not see solution:
https://stackoverflow.com/questions/2602133/java-string-replaceall-regex
https://stackoverflow.com/questions/3935741/java-string-replaceall-regex-question
https://stackoverflow.com/questions/19964098/java-1-3-string-replaceall-replacement

Krunal
  • 79.9k
  • 49
  • 255
  • 268
lang-java

AltStyle によって変換されたページ (->オリジナル) /