Reputation: 1058
String1: \txd\tbuba:pub|rub|spo-os|ix|beach|app|one|op|sono\tadT\tad\t
String2: \txd\tbuba:pub\tadT\tad\t
I have two sample strings and need common regex to extract pub|rub|spo|ix|beach|app|one|op|sono
and pub
I tried buba:(\w(.)*(-os)?)\\t
but not working.
Please assist.
Upvotes: 0
Views: 68
Reputation: 163217
You could use
buba:(\w+(?:\|\w+(?:-os)?)*)\\t
Explanation
buba:
Match the string buba:
(
Capture group 1
\w+
Match 1+ word chars(?:\|\w+(?:-os)?)*
Optionally repeat |
and 1+ word chars with optional -os
)
Close group 1\\t
Match \t
The value is in capture group 1.
Or a broader variant
buba:(\w+(?:\|[\w-]+)*)
Upvotes: 1