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

160 Views Asked by At

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+(.*)

1

There are 1 best solutions below

0
Barmar On

. 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