0

I have following sourceString

|User=gmailUser1|login with password=false|addition information=|source IP location=DE|

I want to extract everything between pipes in key value pair. In this case

  1. User=gmailUser1
  2. Login with password=false
  3. addition information=
  4. Source IP location=DE

My regex pattern is giving me the entire string.

\|(\b+)=(\b+)\|
Community
  • 1
  • 1
  • You should probably be tokenizing on the pipe, not what's between them. What language are you doing this in? – Bill the Lizard Sep 14 '17 at 19:47
  • Am trying with vbs – user8611198 Sep 14 '17 at 19:48
  • Comments are for asking questions to clarify the question. Details like this should be int he body of the question. You should also use the VBScript tag, assuming it exists. –  Sep 14 '17 at 20:21
  • Your answer is here: https://stackoverflow.com/q/14103510/1531971 –  Sep 14 '17 at 20:22
  • If an answer helped you, please mark the answer. If not, then maybe add a comment so we can help you further. – spaark Sep 20 '17 at 04:19

2 Answers2

1

Try with the expression:

/\|([^=|]+)=([^|]*)/g

or if you just want the pattern:

\|([^=|]+)=([^|]*)

Depending on your environment you will be able to get captures of group 1 and 2 for each key-value pair.

(I'm not able to test it out right now.)

Update 1: I did a short test and adapted it with the optimization of Wiktor Stribizew.

Update 2: Short explanation of the regex used:

The \b in your pattern means word boundary and does not represend a sign. You cannot combine it with +. See also What is a word boudary.

The first group ([^=|]+) matches anything that is not a = or a | with at least one character.

The second group ([^|]*) matches anything that is not a = with zero or more characters (addition information has an empty value).

spaark
  • 701
  • 10
  • 17
0

Try this:

\w+(=|\s|\w+)

this match:

\w+ = numletter chars and a matching group

(=|\s|\w+) = a = sing, blank space or another numletter group

Abe
  • 1,357
  • 13
  • 31