String urlString=”http://myApp:8080/new/bin/save/SellerMyPage/WebHome”
i want to check whether above string contains the string “MyPage” between two forward slashes. Also it should be in the end between the slashes and should be prefixed
with some characters. here is the result i am expecting
"http://myApp:8080/new/bin/save/SellerMyPage/WebHome" should return true
"http://myApp:8080/new/bin/save/SellerMyPage1/WebHome" should return false(its not ending with MyPage)
"http://myApp:8080/new/bin/save/MyPage/WebHome" should return false(MyPage is not prefixed with any any character)
Looks like i need to take resort of regex for the same? Would appreciate if somebody can help me out regarding regex?
If it contains , i want to extract that string in first case it should return SellerMyPage
For extracting part i used below code snippet but to me iam not convinced it is optimized way. I am sure there should be better way than this?
String extractedElement="";
String[] urlSpliArray=urlString.split("/");
for(String urlElement:urlSpliArray)
if(urlElement.endsWith("MyPage"))
{
extractedElement=urlElement;
}
1 Answer