Himanshi
Himanshi

Reputation: 3

Regular expression to extract values

I have this pattern and I need to extract values corresponding to 'key:' and 'value:'. I have tried a lot of variations for RegExp patterns but no success. Can anyone help me?

 [Element Mapping -- Key: 111111111 Value: MyValue - MyName, Element Mapping -- Key: 220002222 Value: My-Val - MyName ].

My expected values are individually:

111111111
MyValue - MyName
20002222
My-Val - MyName

Upvotes: 0

Views: 371

Answers (2)

mellamokb
mellamokb

Reputation: 56769

Try this as your regular expression

/Element Mapping -- Key: (\d+) Value: ([^,\]]*)/

http://rubular.com/r/cJLtqCP8j7

Upvotes: 1

richo
richo

Reputation: 8989

Why are you trying to do this with regex?

I would suggest parsing it properly with the same tool that wrote it?

Upvotes: 0

Related Questions