Questions tagged [replaceall]

The replaceAll() method in Java is used to replace parts of a string using a regular expression.

The replaceAll() method in Java is used to replace parts of a string using a regular expression.

Note that in most languages, including Java, the String object is immutable. In other words, you can't change it. If you want a slightly different string value then you have to create a second object. For that reason, replaceAll() does not actually change the string being searched, but rather returns a new string that is the result of the specified search and replace actions.

780 questions
-1
votes
1 answer

How to unescape special characters in Rust?

For example, if you have escaped string like Hello wo\\\\rld.txt you want to unescape it and make it, Hello wo\\rld.txt essentially making, \\ -> \, \\r -> \r, \\n -> \n, etc I tried doing string replace like: out = out.replace("\\", "\"); but…
-1
votes
1 answer

Problem deleting "}" character in Android Java

I have a method in java in an android app that gets a String and extracts some information from it. Input has a fixed format. It contains "}" characters and they need to be deleted in process of extracting information. I tried to delete them…
Javadi
  • 15
  • 2
-1
votes
2 answers

Replacing string for only one time in Java?

Saying that there are String A = "aabbccdd" and String B = "abcd", is there any way to remove the matching characters of String B towards String A for only one time? Expected output is A = "abcd". I know it will solve the problem when using for…
YeonSoo
  • 33
  • 7
-1
votes
1 answer

Java: is "$1" a placeholder?

I was given a Java exercise: Break up camelCase writing into words, for example the input "camelCaseTest" should give the output "camel Case Test". I found this solution online, but I don't understand all of it public static String…
-1
votes
1 answer

ReplaceAll for big comma separated string

I have used the replaceAll method of Javascript to replace the occurrences of character code " to Double Quotes in a big comma separated String. I really worry whether it will cause any issues or performance issues when deal with large amount of…
-1
votes
1 answer

Replacing a word with another word without replacing another word which contains a similar substring in the same sentence in Javascript

I'm trying to replace a word with another word, specifically "has" with "had". But the string contains the word "hash" which has the substring "has" so it also gets replaced. What can I do to fix this? function replace() { sentence =…
Chi Le
  • 19
  • 6
-1
votes
3 answers

Replace tags with new tags with innerHTML to set to id

I have the following text: Send to Example Mark and Testing James a new Document And would like to obtain the following code: Send to 1 and 3 a new Document The number…
Daniele
  • 13
  • 2
-1
votes
2 answers

How can one use the Java replaceAll() method to using multiple strings in one method?

I was wondering if it was possible to use the replaceAll() String method in Java with multiple Strings to search. In other words, is it possible to have multiple Strings get searched in one replaceAll() method? I tried this: foo.replaceAll("a" ||…
vPrototype
  • 109
  • 1
  • 8
-1
votes
2 answers

How do I use the replaceAll() function recursively?

The program should allow a user to enter a string, a substring they wish to find and another string with which they wish to replace the found substring. The output of your program should be similar to the output given below: Please enter a string:…
-1
votes
3 answers

JS replace all matching id values

A website has multiple pages with imported HTML from another page with id tags that need to be simplified. It currently looks like this.

Anything

-1
votes
3 answers

java String replaceAll " to \\"

I want to replace " in my string to \\" for later use by Javascript JSON.parse(...), I try the following test String name = "\"ab\"c"; System.out.println("name before escape="+name); String name1 = name.replaceAll("\"",…
user1169587
  • 1,104
  • 2
  • 17
  • 34
-1
votes
2 answers

Replace one set of characters with another set of characters

I am writing code to convert Roman Numbers to Decimal Numbers. I was wondering if this line could be optimised? String s = "MCMXCIV"; String code = s.replaceAll("I", "a") .replaceAll("V", "b") .replaceAll("X", "c") …
Lovesh Dongre
  • 1,294
  • 8
  • 23
-1
votes
2 answers

How to regex number, and to keep comma, whitespace and dot in the output string?

I've got a problem with a regex, I need to extract a string from text and keep whitespace, coma and dot in the number(if it is exists), example: Lorem impsum the price is:196 000,2545.20 $ blablabla, Output: 196 000,2545.20 Example2:2530002545.20…
-1
votes
1 answer

How can I replace all occurrences of a specific substring in java?

I am attempting to replace a white space in a string that occurs before a closing parentheses or after an opening parantheses. For example the string "8 / ( 1 + 3 ) - 6 ^ 2" Should be changed to: "8 / (1 + 3) - 6 ^ 2" I am assuming this will use…
-1
votes
2 answers

JavaScript Replace Text with Image

I'm still newbie, I want to replace all 'Snowman' text in the string chain for images of snowman. Is there any easy possibility to do this in only JS? Ok I forgot this is important too. It gets string chains actually from my Twitch channel chat to…
TechNeck
  • 1
  • 2