java - Regex - Finding numbers in a certain String after a char and then editing them? -


i have multiple files in directory, , files contain multiple string such as:

details: 0 5453 293

details: 1 4223 123

details: 2 8885 231

the problem since have multiple files, each file has different details different numbers.

how replace numbers after 0, 1, , 2?

i can't do:

.replace("details: 0 5453 293", "details: 0");

since not know numbers there after 0 other files.

you can use string.replaceall method regular expression this.

using lookaround assertion:

string s = "details: 2 8885 231"; s = s.replaceall("(?<=^details: \\d).*", ""); system.out.println(s); //=> "details: 2" 

or using capturing group:

string s = "details: 2 8885 231"; s = s.replaceall("^(details: \\d).*", "$1"); system.out.println(s); //=> "details: 2" 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -