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 .replaceAll the sign "( "

I have a code like this public class New { public static void main(String args[]) { String s1 = "( Hey!! You're my everything )"; String replaceString=s1.replaceAll("(","buka kurung"); System.out.print(replaceString); } } i wanna replace that (…
Jazuly
  • 321
  • 1
  • 4
  • 15
-1
votes
5 answers

How can I replace the entire HTML of a page, or its body content, via an AJAX call's success callback?

I need to replace the entire HTML of a page, or its body content (rather than append more html to the existing content). The accepted answer here showed me how to return data, but adding it to "body" doesn't quite work. This is the jQuery I have…
-1
votes
2 answers

replaceAll in java giving wrong output

replaceAll is giving wrong output for the following code:- package javaapplication3; public class JavaApplication3 { public static void main(String[] args) { try { String sa = "LTD."; sa =…
-1
votes
1 answer

Triplicate all digits in a string

I have a string containing digits like "abc123" and I want every digit to show up 3 times like this: "abc111222333". Is there a way to do this with replaceAll("\\d+.*", ???) whereas the ? is whatever digit was found? Respectively, is there anything…
sinclair
  • 2,812
  • 4
  • 24
  • 53
-1
votes
2 answers

Java replace Japanese characters with \\p{Katakana} regular expression

i have followed that link and the user "slevithan" offer using \p{Katakana} public static void main(String[] args) { String str = "マイポケット (1).csv"; str= str.replaceAll( "[\\p{Katakana}]", "_");//.replaceAll("\\p{Z}", "_"); …
2Big2BeSmall
  • 1,348
  • 3
  • 20
  • 40
-1
votes
7 answers

Java "||" String replace by "OR"

I have a string like "age = 18 || name = 'Mistic' || civilstatus = 'married' || gender = '0' " and i need to replace "||" by "OR". I tryied following code. System.out.println("age = 18 || name = 'Mistic' || civilstatus = 'married' || gender =…
Lakmal Vithanage
  • 2,767
  • 7
  • 42
  • 58
-1
votes
1 answer

Removing Spaces from Scanner (System.in) Input

Right now I'm working on taking an equation, in "infix" notation and remove any spaces within that string prior to performing the rest of my program. Right now, without any spaces in the string, I receive the correct "Postfix" equation in return. …
Pwrcdr87
  • 935
  • 3
  • 16
  • 36
-1
votes
3 answers

I want to replace a string with it's grammatical opposite and print in an "Edit text" in android studio?

I have written this code to replace "is" with "was". I am not able to do so for more than one word. Can anyone please help me do so? public class MainActivity extends AppCompatActivity { EditText editText1, editText2 ; Button button; …
R.ven
  • 23
  • 3
-1
votes
1 answer

Having issues with replaceAll()

Maybe I am using replaceAll incorrectly, but I am unable to find why it acts this way. I want to simply remove a $ sign from a string and then output the string. public class Example{ public static void main(String[] args){ String s = "$50"; …
Sythe
  • 143
  • 1
  • 1
  • 9
-1
votes
1 answer

remove key=value from a String?

I have a String which is like this:
john
  • 11,311
  • 40
  • 131
  • 251
-1
votes
2 answers

How to remove certain html tags from a String with replaceAll?

I have a string including different kinds of html tags. I want to remove all and tags. I tried: string.replaceAll("", ""); string.replaceAll("", ""); But it doesn't work. Those tags still remain in the string. Why?
Steve Waters
  • 3,348
  • 9
  • 54
  • 94
-1
votes
2 answers

Replace unwanted footer text with empty space

how to replace unwanted footer text? ---  This email has been checked for viruses by Avast antivirus software.  http://www.avast.com html code footer:  


---
Strike01
  • 3
  • 2
-1
votes
2 answers

Notepad ++ : How to Replace as the description

I have lines like these abye/>abye abys/>abys aced/>aced aces/>aces I want it like this abye abys aced aces Is it possible? If it is then please someone show me the way.
-1
votes
2 answers

File read, changed but how to write out?

Ok, forgive my beginner-ness and please tell me how I can output my text from "before.txt" into a fresh new file called "after". Obviously I have altered the text along the way to make it lower-case and eliminate non alphabetic characters. import…
-2
votes
1 answer

How to replace two words with blank space in a comma-separated String using regex in Java?

I have the following String ""00001","Open","2020-10-23 12:45","2022-10-20 15:48","Error not found","Alex Smith","NO ERROR","ErrorApp","FOB","CNSHA","GB","Plane","MODEL","2020-10-24 00:00","New","1","","2022-10-20 15:48"" I need to replace the 4th…