This is my data
ZP-S,ZB-MA-S,ZB,ZB-MA-M,ZB-MA-B,ZP,PY,ZB-ME-S,ZB-ME-M,PY,ZB-ME-B,PY-S,PY-M,PY-B,ZP-B,ZB-MA-S-LS-MLE-PES
This is my regex, which I tried
(^|,)(ZB)-?[^,]+(,|$)
my intention here is to check whether within comma separated list has word which starts with (ZB)
can contain ( hypen and [A-Za-z0-9_]+)
recursively
Expected match are as follows
ZB-MA-S
ZB
ZB-MA-M
ZB-MA-B
ZB-ME-S
ZB-ME-M
ZB-ME-B
ZB-MA-S-LS-MLE-PES
ZB[^,]*(?=,?)
What I am looking for is to match any comma separated value that starts with the searched string ZB
and keep matching as long as I don't hit a ,
.
Hope this helps
Try ZB[a-zA-Z0-9\-\_]*
This will match all alphanumeric characters, underscore, and hyphen following ZB
This should do it
(ZB[\w\-]*)
Demo here
https://regex101.com/r/D1dRxd/3
ZB
matches the characters ZB
literally (case sensitive)\w
matches any word character (equal to [a-zA-Z0-9_])\-
matches the character - literally (case sensitive)*
Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed