html - Replace and modify String using regex in java -
i have part of html website in below string format:
srcset=" /tesla_theme/assets/img/homepage/mobile/homepage-models--touch@200w.jpg?20170808 200w, /tesla_theme/assets/img/homepage/mobile/homepage-models--touch@338w.jpg?20170808 338w, /tesla_theme/assets/img/homepage/mobile/homepage-models--touch@445w.jpg?20170808 445w, tesla_theme/assets/img/homepage/mobile/homepage-models--touch@542w.jpg?20170808 542w, /tesla_theme/assets/img/homepage/mobile/homepage-models--touch@750w.jpg?20170808 750w"
i want add http://tesla.com in front of urls in srcset element http://tesla_theme/assets/img/homepage/mobile/homepage-models--touch@750w.jpg?20170808 750w
i believe done using regex, not sure.
how do using java if have multiple srcset elements in html string variable, , want replace of srcset url.'s , add server url in front?
note: /tesla_theme not consistent, cannot use replaceall, instead, have use regex.
you can use string class replace method below, replace "/_tesla" in given string. no special regex required unless have kind of pattern instead of "/tesla"
string srcset=" /tesla_theme/assets/img/homepage/mobile/homepage-models--touch@200w.jpg?20170808 200w, /tesla_theme/assets/img/homepage/mobile/homepage-models--touch@338w.jpg?20170808 338w, /tesla_theme/assets/img/homepage/mobile/homepage-models--touch@445w.jpg?20170808 445w, tesla_theme/assets/img/homepage/mobile/homepage-models--touch@542w.jpg?20170808 542w, /tesla_theme/assets/img/homepage/mobile/homepage-models--touch@750w.jpg?20170808 750w"; string requiredsrcset = srcset.replace("/tesla_", "http://tesla_");
Comments
Post a Comment