Extracting two strings from quotations in Java using regex?

Posted by user656710 on Stack Overflow See other posts from Stack Overflow or by user656710
Published on 2011-03-12T15:52:47Z Indexed on 2011/03/12 16:10 UTC
Read the original article Hit count: 164

Filed under:
|
|
|

Hi everyone,

I'm new to using patterns and looked everywhere on the internet for an explanation to this problem.

Say I have a string: String info = "Data I need to extract is 'here' and 'also here'";

How would I extract the words:

here
also here

without the single quotes using a pattern?

This is what I have so far...

Pattern p = Pattern.compile("(?<=\').*(?=\')");

But it returns ( here and 'also here ) minus the brackets, that is just for viewing. It skips over the second piece of data and goes straight to the last quote...

Thank you!

© Stack Overflow or respective owner

Related posts about java

Related posts about regex