How to negate numbers followed by a whitespace? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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🇮🇳

25th Sep 2020, 7:12 PM
Александр
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..
25th Sep 2020, 7:27 PM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 I've tried, but it didn't work. Thank you anyway!
25th Sep 2020, 7:35 PM
Александр
0
OK. I got it. Just remove {1,} it works. I checked it.. Try it or reply for more Александр
25th Sep 2020, 7:40 PM
Jayakrishna 🇮🇳
0
No, still not working, Jayakrishna🇮🇳 ;( Since I use it in replaceAll() method I need to negate this expression.
25th Sep 2020, 8:23 PM
Александр
0
public class Program { public static void main(String[] args) { String s = "sdf1 fgg21 hj"; System.out.println(s.replaceAll("\\d+\\s", "")); } }
25th Sep 2020, 8:27 PM
Jayakrishna 🇮🇳
0
Oh, my bad Jayakrishna🇮🇳 . Is there any way to do the opposite now? To get the output like: sdffgghj
25th Sep 2020, 8:32 PM
Александр
0
Opposite means? How you get opposite as same answer..? Ex?
25th Sep 2020, 8:35 PM
Jayakrishna 🇮🇳
0
Yeah, but I have found the solution :3 Thanks alot, Jayakrishna🇮🇳 !!!
28th Sep 2020, 6:31 AM
Александр