I have text as follows:
"text","1","more, more text","3"
Could anyone kindly show me what regex delimeters I have to use to get the following:
text
1
more, more text
3
I was reading the Sun tutorial here, up until "Methods of the matcher class" but I am still at a loss. Thanks!
If it were something like text,1,more
it would be easy enough, but unfortunately it's not like that. Any ideas?
Try this pattern:
"(.+?)"
It will match 1 or more characters between double quotes. The part of the text between the quotes is available as
matcher.group(1)
.Look at the javadoc for
Pattern
class to learn more. Also, look atmatcher.find()
method.You could get every part that start with an
"
and finish with another"
and then substring the first and last character of each part.You can either go straight for the split() method like this:
(beware that this returns a length 5 array, with the first position being an empty string)
Or, if you want to use a Pattern/Matcher, you can do it like this:
You can try something like that. I know, it is not good solution, but it can help you :)
seems it is! in java string you can use
You can test it online here: http://www.regexplanet.com/simple/index.html
you could try this
[^\"]+(?<!\",?)