good way to parse two different patterns in java
I have data coming as following:
key value
<foo.bar> <foo>
<foo bar> foo
<foobar1> foo
And I want to parse it...
obj.setKey(key);
obj.setValue(value);
Now how do i parse this in one function:
So far I have.
public void setNTriples(String text){
Pattern pattern = Pattern.compile("<(.*?)>");
Matcher matcher = pattern.matcher(text);
int count = 0;
while(matcher.find()) {
if (count == 0){
setKey(matcher.group(1));
count +=1;
}
else if (count == 1){
setValue(matcher.group(1));
count +=1;
}
}
But the above fails for example two and three as those values doesnt have
"<" and ">" in it?
How do i solve this?? Thanks
No comments:
Post a Comment