Parsing complex string using regex
Posted
by wojtek_z
on Stack Overflow
See other posts from Stack Overflow
or by wojtek_z
Published on 2010-06-15T17:08:47Z
Indexed on
2010/06/15
17:12 UTC
Read the original article
Hit count: 430
My regex skills are not very good and recently a new data element has thrown my parser into a loop
Take the following string
"+USER=Bob Smith-GROUP=Admin+FUNCTION=Read/FUNCTION=Write"
Previously I had the following for my regex : [+\\-/]
Which would turn the result into
USER=Bob Smith
GROUP=Admin
FUNCTION=Read
FUNCTION=Write
FUNCTION=Read
But now I have values with dashes in them which is causing bad output
New string looks like "+USER=Bob Smith-GROUP=Admin+FUNCTION=Read/FUNCTION=Write/FUNCTION=Read-Write"
Which gives me the following result , and breaks the key = value structure.
USER=Bob Smith
GROUP=Admin
FUNCTION=Read
FUNCTION=Write
FUNCTION=Read
Write
Can someone help me formulate a valid regex for handling this or point me to some key / value examples. Basically I need to be able to handle + - / signs in order to get combinations.
© Stack Overflow or respective owner