java - replace string between first two occurrence of '&' chars -
how can replace string between first & , next & only:
public class test02 { public static void main(string[] args) { string xyz = "&axy=asdsd&ram=2 gb4 gb&asd=sdsd&"; string x = xyz.replaceall("&ram=.*&", "&ram=8 gb&"); system.out.println(x); } } my input - &axy=asdsd&ram=2 gb4 gb&asd=sdsd& output - &axy=asdsd&ram=8 gb&
but want- &axy=asdsd&ram=8 gb&asd=sdsd&
only want change middle part.
i making search filter. if api building query exists love know.
thanks bobble,
this worked... '.?' instead of '.' ..
public class test02 {
public static void main(string[] args) { string xyz = "&axy=asdsd&ram=2 gb4 gb&asd=sdsd&"; string x = xyz.replaceall("(&ram=.*?)&", "&ram=8 gb&"); system.out.println(x); } }
now out put-- &axy=asdsd&ram=8 gb&asd=sdsd&
Comments
Post a Comment