-2

I'm using Java, and I want to remove all the occurrences of \ from my string (something like http\:\/\/news.investors\/092115\-772034\-red\-hat\-tops\-16\-views\-beat.html )

I'm using replace all but I don't know how is the regular expression to do this.

Pshemo
  • 122,468
  • 25
  • 185
  • 269
Matteo Amadei
  • 67
  • 1
  • 4
  • 2
    `myString.replace("\\", "")`. Don't use `replaceAll` unless you _need_ Regex. – Boris the Spider Sep 23 '15 at 13:51
  • Can you show us how you are using `replace` and what errors/problems you are getting? – Pshemo Sep 23 '15 at 13:51
  • Don't use regex unless your current solution isn't working. Short and sweet. – Shotgun Ninja Sep 23 '15 at 13:55
  • 2
    Possible duplicate: [Java, Removing backslash in string object](http://stackoverflow.com/questions/5104192/java-removing-backslash-in-string-object) – Pshemo Sep 23 '15 at 13:56
  • @Pshemo you have the gold java badge (kudos man), can you single-handedly mark the question as a dupe? – Blake Yarbrough Sep 24 '15 at 15:27
  • @LanguidSquid I can't change my close vote reason. I already voted to close it as off-topic because there was no code which will let us reproduce OP problem. After that I was able to find that duplicate so I posted that comment, but I can't close-vote again. – Pshemo Sep 24 '15 at 15:32
  • @LanguidSquid Feel free to flag this question as duplicate. Maybe it will place it in close queue. – Pshemo Sep 24 '15 at 15:33
  • 1
    @Pshemo I have flagged it as a dupe, I suppose we are at the mercy of the community at this point, cheers – Blake Yarbrough Sep 24 '15 at 15:36
  • @LanguidSquid If I remember correctly, if someone will *vote* to close question as duplicate OP is able to accept that duplicate which can also make things go faster. But I am not sure if that is the case of duplicate *flags*. We will see. – Pshemo Sep 24 '15 at 15:44

1 Answers1

-1
public static void main(String[] args) {
    String myUrl = "http\\:\\/\\/news.investors\\/092115\\-772034\\-red\\-hat\\-tops\\-16\\-views\\-beat.html";
    myUrl = myUrl.replace("\\","");
    System.out.println(myUrl);
}

output:

http://news.investors/092115-772034-red-hat-tops-16-views-beat.html

from: Java, Removing backslash in string object

Community
  • 1
  • 1
Blake Yarbrough
  • 2,286
  • 1
  • 20
  • 36
  • If you believe that question A contains answer to question B, then instead of reposting that answer flag question B as as duplicate of question A. – Pshemo Sep 23 '15 at 14:22
  • You have already flagged it, I up-voted the flag. I answered the question in the meantime so that OP could be on his way. – Blake Yarbrough Sep 23 '15 at 14:37
  • No, I didn't flag it because I couldn't after voting to close this question for another reason. Anyway even if I would flag it it still doesn't mean that you should duplicate answers. – Pshemo Sep 23 '15 at 14:45