L
Lee
Sorry, I'm used to Perl and am stumbling badly at Java's regular
expressions.
I'm trying to extract strings from withing quotes. IE if a line of
data had this:
"Say something" "Say another thing"
I should get 2 matches with the respective quotes in each. This is
the code I'm using:
String line = "\"Say something\" \"Say another thing\"";
Pattern betweenQuotes = Pattern.compile( "\"(.*?)\"" );
Matcher m = betweenQuotes.matcher( line );
System.out.println( "matches: " + m.matches() );
System.out.println( "count: " + m.groupCount() );
System.out.println( "captured quote: " + m.group(1)) ;
It seems like the non-greedy ? isn't working..
I would expect the text between each quote to show up in m.group(1)
and m.group(2)
What am I missing?
Thank you for whatever help you can give.
Lee
expressions.
I'm trying to extract strings from withing quotes. IE if a line of
data had this:
"Say something" "Say another thing"
I should get 2 matches with the respective quotes in each. This is
the code I'm using:
String line = "\"Say something\" \"Say another thing\"";
Pattern betweenQuotes = Pattern.compile( "\"(.*?)\"" );
Matcher m = betweenQuotes.matcher( line );
System.out.println( "matches: " + m.matches() );
System.out.println( "count: " + m.groupCount() );
System.out.println( "captured quote: " + m.group(1)) ;
It seems like the non-greedy ? isn't working..
I would expect the text between each quote to show up in m.group(1)
and m.group(2)
What am I missing?
Thank you for whatever help you can give.
Lee