Sourabh Agrawal
Sourabh Agrawal

Reputation: 9

regex pattern to extract all the comma separated values altogether along with newline i.e. extract entire string

Test String

Address: c8245A626
AliasName: eSrb002359_f1
Igroup Name: rtvclar002359, unjlclar002358-9,
cokeclar00RCB_FC
Protocol: REST

Note: "Igroup Name" field has 3 comma separated values and third value is in newline also.

Required output: rtvclar002359, unjlclar002358-9, cokeclar00RCB_FC

Regular Expression I have tried: Igroup Name:\s+(.*)

Upvotes: -2

Views: 160

Answers (1)

Barmar
Barmar

Reputation: 782285

. doesn't match newlines by default. \s will match any whitespace, which includes newline.

Try

Igroup Name:\s+((?:[\w-]+,\s*)*[\w-]+)

This matches any number (including 0) of values with , after them, followed by a single value with no comma. This will match all the values.

DEMO

Upvotes: 0

Related Questions