I have a string I need to get array (2 - dim) of key->value pairs.
A "match" is when there is a -> between 2 words, mo spaces before and after ->
For example input string:
skip_me key1->value1 key2->value2 skip_me_2 key3->value3 skip_me_3 skip_me -> also
The result should be array:
key1,value1
key2,value2
key3,value3
This is my code:
Pattern p = Pattern.compile( "\\s*([^(->)]+)->([^(->)]+)\\s*" );
Matcher m = p.matcher("skip_me key1->value1 key2->value2 skip_me_2 key3->value3 skip_me_3");
while( m.find() ) {
System.out.println( "Key:" + m.group(1) + "Value:" + m.group(2) );
}
My regex is wrong. Please assist.