java - How can I combine these two Regex statements into one with String.repalceAll() -


i have string,

"36635,36635,36635,36635 36635 36635 36635 36635-36635-36635"

by end of like

36635 36635 36635 36635 36635 36635 36635 36635 36635 36635

i've managed achieve below code.

string original = "36635,36635,36635,36635   36635   36635 36635  36635-36635-36635"; string justspaces =  original.replaceall("[^0-9]", " "); string onespacemax = justspaces.replaceall(" {2,}", " "); system.out.printf("original: %s \n justspaces: %s \n onespacemax: %s", original, justspaces, onespacemax); 

output

original: 36635,36635,36635,36635   36635   36635 36635  36635-36635-36635  justspaces: 36635 36635 36635 36635   36635   36635 36635  36635 36635 36635  onespacemax: 36635 36635 36635 36635 36635 36635 36635 36635 36635 36635 

how can combine 2 regex statements? i've attempted using or | operator no luck.

use:

original = original.replaceall("\\d+", " "); 

\\d+ match 1 or more non-digit (including spaces) , replacement single space.

regex demo


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -