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
-3
votes
2 answers

Java replaceall except first and last character in every word

What I want to accomplish is to replace a sentence to underscore, but except the first and last character in a word. Example: I am walking To: I am w_____g Is this possible with regex?
Cyto
  • 60
  • 1
  • 8
-3
votes
1 answer

Java String ReplaceAll (Regex Help)

I have the following String: String str1= "ABCD"; I want the following String String str2 = "AD" Therefore, I would like something along the lines of this: String str2 = str1.replaceAll("/* SOME REGEX HERE */", ""); How can I write the regex so…
androideka
  • 71
  • 1
  • 11
-3
votes
5 answers

replace in java using regular expression

suppose I have a string String = ".... helllo.... good \"morning\" .....\" " I want to get output as helllo good morning How can I do that using regular expression in Java?
Ronin
  • 2,027
  • 8
  • 32
  • 39
-4
votes
1 answer

c++: how to remove surrogate unicode values from string?

how do you remove surrogate values from a std::string in c++? looking for regular expression like this: string pattern = u8"[\uD800-\uDFFF]"; regex regx(pattern); name = regex_replace(name, regx, "_"); how do you do it in a c++ multiplatform…
-4
votes
1 answer

Need to replace all commas in an AWS lambda using Java 8

First I should lead with how very inexperienced I am with this language. Everything I've tried has blown up. It doesn't seem to like .replace or .replaceAll anyway I've tried to use it. I've used Pattern and Matcher. no go. I need to place this…
-4
votes
3 answers

How do I obtain spaces before prepositions?

I have the string 'WordsofWisdom' and if I apply this: replaceAll("([^_])([A-Z])", "$1 $2") it produces 'Wordsof Wisdom', but what do I have to write to obtain a space before the word 'of'?
krystal
  • 27
  • 6
-4
votes
1 answer

In JDK 1.3 String.replaceall() not working. any alternate solution

I am trying to run below mentioned code in JDK 1.3 and giving error as JDK1.3 does not support string.replaceall strtobeReplaced = strtobeReplaced.replaceall("&","&"); strtobeReplaced = strtobeReplaced.replaceall("].value",""); can anyone…
S Basu
  • 11
  • 2
-4
votes
3 answers

How do you check if the first half of a string is the same as the second half of the string?

how to check if the first half of a string is the same as the second half of the string? (not to be confused with palindromes) This is my code so far. Scanner oIn = new Scanner (System.in); String sFB = oIn.nextLine(); int length =…
JavaFTW
  • 3
  • 3
  • 6
-4
votes
2 answers

Difference in behaviour between String.replaceAll() and StringUtils.replace()

I want to replace all single quotes with escaped single quotes. First I have tried with String.replaceAll("\'", "\\'") but it didn't worked. So, I have tried with StringUtils.replace(String, "\'", "\\'") which worked. Here is the code: String…
Kruti Patel
  • 1,422
  • 2
  • 23
  • 36
-4
votes
1 answer

Java regular expression to remove empty xml nodes and childrens completely

I am struggling to find the best solution. Below is my XML : John doe
-4
votes
1 answer

java.lang.NullPointerException on a simple replaceAll()

I try to write a simple strin replace in java. This is java code. In my test enviroment (linux Ubuntu 12.04 LTS, tomcat) work great. In production enviroment it cause null pointerexception. How to avoid this....in System.out the string is correctly…
-5
votes
2 answers

replaceAll method regex

My sample input is "0X10001,0X10002,0X610001,0X610002" System.out.println(st.replaceAll(regex, "0")); My output should be "010001,010002,610001,610002" 0X should be replaced by 0 --> if length is 7 ""--> if length is 8 what is the regex I have…
Tej4493
  • 1
  • 2
-5
votes
1 answer

Java replace \" with " in a string

I have a JSON response where all the double quotes are delimited with \. So to print contents as JSON format, I need to replace \" with ". I'm using Java's string replaceAll method to do so, but couldn't achieve the same. Something like below to get…
Giri
  • 411
  • 2
  • 18
-7
votes
1 answer

Replace string \ with / android

I need to replace the string "\" with "/" I tried myString.replace("\","/"); but it's kind of syntax it says String literal is not properly closed by a double-quote how can i do it ?
-12
votes
1 answer

JSON Exception for input jsonStringarray

Below is my JSON ["[0288144111, Please check File Values:==>For input string: "N/A", 20180201]","[4403244111, Upload Not Received, 20180201]","[4246244111, Upload Not Received, 20180201]","[7097244111, Upload Not Received, 20180201]","[9917244111,…
1 2 3
51
52