Disclaimer: This question is more from curiosity and will to learn a bit more about Regex, I know it can be achieved with other methods.
I have a string that represents a list, like so: "egg,eggplant,orange,egg"
, and I want to search for all the instances of the item egg
in this list.
I can't search for the substring egg
, because it would also return eggplant
.
So, I tried to write a regex expression to solve this and got to this expression ((?:^|\w ,)egg(?:$|,\w ))
(I used