How to negate numbers followed by a whitespace? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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
ŠŠ»ŠµŠŗсŠ°Š½Š“р