Fetching package name from string input  - java

Posted on 2013-06-10
Last Modified: 2013-06-10

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.


Question by:Sreejith22
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3

Author Comment

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

Expert Comment

by:Sharon Seth
ID: 39235438
use regex
LVL 86

Accepted Solution

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
How our DevOps Teams Maximize Uptime

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


Author Comment

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

Author Comment

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

Expert Comment

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

Quick and dirty - tack this on at the end

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

Open in new window

LVL 86

Expert Comment

ID: 39235611

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mysql jsp example issue 32 96
java mysql insert application 14 68
Find out all repos that a user is most active on Github 1 58
Eclipse neon2 "Java build path" correctness 7 44
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

751 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