Problem: I need to parse a string which consists out of Key-Value pairs.
Keys are separated from values by a "=". Values can contain a "=", but they must be escaped as "\=".
Key1=Text And escaped\= More stuff\=is here Key2=Value number2
Of course the second key can contain an escaped \=, too. Long story short: Values can be a normal string (any character), except that the equal sign must be escaped.
So far I got (?<=\s|^)([\w ]+)=(\w \\=*)?(?=[ \w=]|[$]) , but it only keeps ordinary Key=value pairs, cutting of at whitespaces.
Edit: Thanks to Richard, who provided a perfectly suitable solution.
I will never again mention that Dalek Dave was the poster of the One Millionth Lounge Post, nor that it was complete drivel.
(BTW) i know this isn't the thing you're looking for, but i hope i could at least help you...
Public Function ListItems As List(Of Item)<br />
Dim Result As New List(Of Item)<br />
Dim items As String = "asd=w2342 asd=12333"<br />
Dim parts() As String = Split(items, " ") 'First off i'm gonna split the items devided by spaces<br />
For Each part As String In parts<br />
Dim items() As String = Split(part, "=") 'Second i'm going to split the part into two seperate values<br />
Dim Value1 As String<br />
Dim Value2 As String<br />
Value1 = items(0)<br />
Value2 = items(1)<br />
Result.Add(New Item(Value1, Value2) 'Then you can assign these value to a class or something else you want to use this data in...<br />
Return Result<br />
I hope i could help you a bit in finding an answer to your problem...
But space also can be in the value part, but not in the key part - Am I right?
In that case I'm not sure you have a pure regex solution...
(I would like to have the time to dig in - it's an interesting challenge, unfortunatelly I have not )
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)