0
How to negate numbers followed by a whitespace?
I need to replace all the numbers followed by a whitespace in a string with empty string using String.replaceAll(). I thought regex will be look like this [^\\d+\\s{1}], but it doesn't work. Where I made a mistake? UPD: thanks, Jayakrishna🇮🇳
8 Answers
+ 4
I think, It it backslash \, not /
And {1,}
So try this [\\d+\\s]{1,} not sure....
But here {1,} means 1, more times related..
Try it..
0
Jayakrishna🇮🇳 I've tried, but it didn't work. Thank you anyway!
0
OK. I got it. Just remove {1,} it works. I checked it..
Try it or reply for more Александр
0
No, still not working, Jayakrishna🇮🇳 ;(
Since I use it in replaceAll() method I need to negate this expression.
0
public class Program
{
public static void main(String[] args) {
String s = "sdf1 fgg21 hj";
System.out.println(s.replaceAll("\\d+\\s", ""));
}
}
0
Oh, my bad Jayakrishna🇮🇳 . Is there any way to do the opposite now?
To get the output like: sdffgghj
0
Opposite means? How you get opposite as same answer..?
Ex?
0
Yeah, but I have found the solution :3 Thanks alot, Jayakrishna🇮🇳 !!!