I have a string like:
"GOOG",625.00,"-1.95 - -0.31%"
I'm using this pattern, and it isn't matching. I'm trying to get GOOG. What am I doing wrong?
Pattern pattern = Pattern.compile("^\"([^\"]+)");
Matcher matcher = pattern.matcher(line);
if (matcher.matches()) {
Log.i(TAG, matcher.group(0));
} else {
Log.i(TAG, "no match");
}
The problem is you're not running matcher.find() so the expression is never really evaluated. What you have will work fine if you just change it to:
if (matcher.find()) {
Though this seems like it'd be easier if you just used the String.split method (or better yet, use a library for parsing CSV files):
String temp = "\"GOOG\",625.00,\"-1.95 - -0.31%\"";
String[] parts = temp.split(",");
String symbol = temp[0].replaceAll("\"", "");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With