aspose file tools*
The moose likes Java in General and the fly likes string extraction using regular expressions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "string extraction using regular expressions" Watch "string extraction using regular expressions" New topic
Author

string extraction using regular expressions

pavithra murthy
Ranch Hand

Joined: Feb 06, 2009
Posts: 56
hello friends .

i wanted to read a string from text file "MRN 123456789" . This text is actually obtained from or extracted from a pdf file to text file using pjtext jar file . while extracting to text file it will be in its own format .
i have written a code to extract the above number using regular expressions .
But since the text file contains words like "MRN 123456789E0Liste der Positionen" .this is also displayed on the command prompt indicating the string has been matched according to regular expression.

but i want only MRN 123456789 . how will be able to do this .
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Is that the _exact_ pattern you are looking for? Or are there other possibilities?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Vinu Valayil
Greenhorn

Joined: May 08, 2009
Posts: 5
Hi Pavithra,

As Martijn said, if this is the exact pattern you're looking for, then you could use:



If you know the exact number of digits appearing in that number, you could also use



What is this life if full of care,
We have no time to stand and stare
santosh patil
Greenhorn

Joined: May 14, 2008
Posts: 5
Hi Pavithra

"MRN\\s\\d+" patther will match for MRN 123456789

You can print Matcher object to check lastmatch result.

Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(line);
boolean found = m.lookingAt();

System.out.println(m.toString());
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: string extraction using regular expressions
 
Similar Threads
regular exression for concatenating string in 2 different lines into the same line
how to extract search engine results
partial string extraction
string extraction by giving position as first argument in command prompt
program to extract the full string based on requirement