I have a string with value
"ABC","ONE", "Hello",,,"2019"
I want to replace two consecutively empty values in a CSV file with *
.
Expected output:
"ABC","ONE", "Hello","*","*","2019"
This is what I tried,
line.replaceAll(",,","\"*\"");
But this gives me below output, replacing on first occurrence
"ABC","ONE", "Hello","*","2019"
You may use a regex with lookahead and lookbehind:
(?<=,)(?=,)
And replace it with "*"
Java Code:
repl = str.replaceAll("(?<=,)(?=,)", "\"*\"");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.