Mahesh
Mahesh

Reputation: 39

URL replacement in java

I am trying to replace url with another url.

Below is the example of source url

http://sysserver01.internal.com/web/www/internal/projectwork/resources/injury-prevention-and-recovery/avoiding-injury/overview-of-running-injuries/

so this url should be replace with below url,

http://sysserver01.internal.com/var/www/html/injury-prevention-and-recovery/avoiding-injury/overview-of-running-injuries/

It means if source url comes then the part after resources in source url must be appended with /var/www/html/(and rest of part after resources in source url).

This needs to be happen with rendom set of source url that contains resources string.

I dont have enough knowldege of string manipulation. So please someone help me to solve this query. Please try to solve it in JAVA as I choose this platform for my work.

Upvotes: 0

Views: 5059

Answers (2)

amicngh
amicngh

Reputation: 7899

String originalUrl = "http://sysserver01.internal.com/web/www/internal/projectwork/resources/injury-prevention-and-recovery/avoiding-injury/overview-of-running-injuries";

String newUrl = originalUrl.replaceAll("web/www/internal/projectwork/resources", "var/www/html");

Upvotes: 3

Austin Heerwagen
Austin Heerwagen

Reputation: 663

String originalUrl = "http://sysserver01.internal.com/web/www/internal/projectwork/resources/injury-prevention-and-recovery/avoiding-injury/overview-of-running-injuries";

String newUrl = originalUrl.replace("web/www/internal/projectwork/resources", "var/www/html");

Upvotes: 1

Related Questions