Solved

Fetching package name from string input  - java

Posted on 2013-06-10
7
735 Views
Last Modified: 2013-06-10
Hi:

I need to write a function which accepts a url as string. The function should do the following:

If the input is of the first url pattern, it should get the content after the last '/' in the url and before the .apk

If the input is of the second url pattern, it should get the content after the ?id= and before &feature


ie; in short, it should be returning package name from url. How can I accomplish this through java? Any help is appreciated.

PATTERN 1

http://abc.com/data/applications/net.feathertech.mediterraneanrecipes.apk
http://abc.com/data/applications/com.a731412505508e759b5b9717a.a36562546a.apk
http://abc.com/data/applications/com.petwisewebsites.mobile.apk

PATTERN 2

https://play.google.com/store/apps/details?id=com.apofiss.yinthecatlite&feature=personalized-recommendations#?t=W251bGwsMSwxLDIxMywiY29tLmFwb2Zpc3MueWludGhlY2F0bGl0ZSJd


https://play.google.com/store/apps/details?id=com.apofiss.pandadumplinglite&feature=more_from_developer#?t=W251bGwsMSwxLDEwMiwiY29tLmFwb2Zpc3MucGFuZGFkdW1wbGluZ2xpdGUiXQ..

https://play.google.com/store/apps/details?id=com.apofiss.chameleon&feature=more_from_developer#?t=W251bGwsMSwxLDEwMiwiY29tLmFwb2Zpc3MuY2hhbWVsZW9uIl0.
0
Comment
Question by:Sreejith22
  • 3
  • 3
7 Comments
 

Author Comment

by:Sreejith22
ID: 39235365
please let me know if any clarification regarding question is required
0
 
LVL 12

Expert Comment

by:Sharon Seth
ID: 39235438
use regex
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 300 total points
ID: 39235457
 s = s.replaceAll(".*/([^&]+).*", "$1").replaceAll(".*=(.*)", "$1");

Open in new window

The above is possibly OK, although it should be possible to do it more elegantly
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:Sreejith22
ID: 39235458
any code snippet is much appreciated. I know regex is the possible way, but , sorry I do not have expertise using it.
0
 

Author Comment

by:Sreejith22
ID: 39235472
Hi cehj,
 it does not exclude apk in first pattern
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39235486
Well you didn't ask for that ;)

Quick and dirty - tack this on at the end

.replaceAll("\\.apk$", "");

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39235611
:)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Core Java. What output will be and why ? 6 66
Java Message handling in Service Layer 3 58
Java Options in Zimbra Server 2 46
split string containing \r\n in Java 46 38
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now