I have a string that has two single quotes in it, the '
character. In between the single quotes is the data I want.
How can I write a regex to extract "the data i want" from the following text?
mydata = "some string with 'the data i want' inside";
String dataIWant = mydata.split("'")[1];
See Live Demo
as in javascript:
the actual regexp is:
/'([^']+)'/
if you use the non greedy modifier (as per another post) it's like this:
it is cleaner.
In Scala,
Because you also ticked Scala, a solution without regex which easily deals with multiple quoted strings:
You don't need regex for this.
Add apache commons lang to your project (http://commons.apache.org/proper/commons-lang/), then use: