Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a separator in string using regular expressions? [closed]

Tags:

regex

I want a string, which must be in parentheses () and separated with a comma , something like: (aaa),(bbbb),(cccccccc)

How could I match that using regular expression?

like image 972
zeder127 Avatar asked Feb 14 '26 04:02

zeder127


1 Answers

You can try this

^(?!,)(,?\(\w+\))+$

^ marks the beginning of string

$ marks the end of string

Both ^,$ are required else it would match in between

\w+ matches 1 to many of [a-zA-Z\d_]

,? would optionally match ,

^(?!,) would look for , at the beginning of string and if it finds it,it doesn't match further.If it doesn't find,it returns to the previous position i.e at the start of string

like image 114
Anirudha Avatar answered Feb 15 '26 19:02

Anirudha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!