Java split and replace -
i have following string
string path = "(tags:homepage).(tags:project mindshare).(tags:5.5.x).(tags:project 5.x)";
i used following code,
string delims = "\\."; string[] tokens = path.split(delims); int tokencount = tokens.length; (int j = 0; j < tokencount; j++) { system.out.println("split output: "+ tokens[j]); }
current output
split output: (tags:homepage) split output: (tags:project mindshare) split output: (tags:5 split output: 5 split output: x) split output: (tags:project 5 split output: x)
end goal convert string
string newpath = "(tags:homepage)(tags:project mindshare)(tags:5.5.x)(tags:project 5.x)";
you can use positive lookbehind achieve :
string path = "(tags:homepage).(tags:project mindshare).(tags:5.5.x).(tags:project 5.x)"; string newpath = path.replaceall("(?<=\\))\\.", ""); // periods preceeded `)` system.out.println(newpath);
o/p :
(tags:homepage)(tags:project mindshare)(tags:5.5.x)(tags:project 5.x)
Comments
Post a Comment