jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "string extraction using regular expressions" Watch "string extraction using regular expressions" New topic

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

Joined: Jun 24, 2003
Posts: 3275

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

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

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();

I agree. Here's the link: http://aspose.com/file-tools
subject: string extraction using regular expressions
It's not a secret anymore!