java - Regex to find key->value in string -


i have string need array (2 - dim) of key->value pairs.

a "match" when there -> between 2 words, mo spaces before , 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 array:
key1,value1
key2,value2
key3,value3

this 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 wrong. please assist.

matches word characters (letters, digits, , underscore _)... many can

pattern.compile( "(\w+)->(\w+)" ); 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -