This is a ((?:(?:apple|orange|peach)/?)+)
will match
This is a apple/orange/peach.
whatever the order is .
You will get only one capturing group representing the all list.
(here "apple/orange/peach").
- '
(?:apple|orange|peach)
' means: match one of those three terms, do not capture it
- '
(?:.../?)+
': match a string finished by '/' or not, multiple times
- '
(...)
': capture the all list.
This is an apple <-match This is an orange <-match This is a peach <-match This is a banana <-no match.
This is a (apple|orange|peach)
is enough: [apple|orange|peach]
that you tried is actually a character class, and would match any 'a', 'p', '|', 'o', ... etc.