How to get this substring?

Posted on 2006-06-29
Last Modified: 2008-02-26

The above is a string which I want to get the "A6.txt" out of it, the substring after it ".ExtractReport.pdf" and the string before it "@BoaFromExtract.boaTest." will always be constant.  However, the A6.txt can varies in size as I can have A12312321.txt, B23424.txt ect......

I know this has to do with Substring manipulation and trimming my string but I can not seem to come up with a clean method to do it, please help.


btw I store the orignal string in a String array.
Question by:fylix0000
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
  • 5
  • 4
LVL 14

Accepted Solution

hoomanv earned 500 total points
ID: 17012802
           Pattern p = Pattern.compile("BoaFromExtract\\.boaTest\\.(.+)\\.ExtractReport\\.pdf");
            Matcher m = p.matcher("C:\\ViaSafe\\Channel/boaTest/BoaFromExtract/report/done/1151076810520.0@BoaFromExtract.boaTest.A6.txt.ExtractReport.pdf");

Author Comment

ID: 17013041
Tried to run this but the compile method does not seem to work, I check for Patter.method in my IDE but could not see compile either.
LVL 14

Expert Comment

ID: 17013049
have you imported java.util.regex.* ?
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.


Author Comment

ID: 17013183
I had import import java.util.regex.Matcher; only before
but eafter I put in import java.util.regex.*; then i still get the same error.

Focus on error gives me : The method compile(ClassGenerator, MethodGenerator) in the type Expression is not applicable for
 the arguments (String)

Sorry I am quite new to this Pattern so I am kind of clueless.
LVL 14

Expert Comment

ID: 17013221
what is the exact phrase of compile error ?

Author Comment

ID: 17013237
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
      The method compile(ClassGenerator, MethodGenerator) in the type Expression is not applicable for the arguments (String)
      The method matcher(String) is undefined for the type Pattern

      at name_string.main(
LVL 14

Expert Comment

ID: 17013242
java.util.regex.Pattern p = java.util.regex.Pattern.compile("BoaFromExtract\\.boaTest\\.(.+)\\.ExtractReport\\.pdf");

Author Comment

ID: 17013249
Actually , nevermind...somehow my IDE put in import;

will try again, as I took it out and looks good so far.

Author Comment

ID: 17013254
Thank you, worked like a charm :)

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

726 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