Regular expression for something+something+something ... +something?
Sorry because of my great english and brain -> keyboard connection
Regular expression for something+something+something ... +something?
Sorry because of my great english and brain -> keyboard connection
If the "something" is always a word and needs at least two entries
\w(\+\w)+
or for any repeating sequence
\w(\+\w)*
You just have to escape the '+' and the '.' as they are reserved.
For example, in ruby:
/something\+something\+something \.\.\. \+something/
You can escape the +
metacharacter using \+
in your regular expression, if that's what you're asking.
Based on the comment clarifying the question, here's an updated answer:
([a-z]+\+)*[a-z]+
or
[a-z]+(\+[a-z]+)*
As an alternative, would a string split method work?
"Or+Something+like+that".split('+')
/\w+(\s*\w+)*(\+\w+(\s*\w+)*)*/
This should also match phrases of multiple words, if you need that. It also matches non-alpha characters, but you can replace \w with [a-z] if you explicitly want to exclude everything but letters. Just make sure you specify the regex to be case insensitive if you expect capital letters.
edit: commenter below noticed I didn't have the plus sign after the \w 's, so it was only matching a single character at a time. \w+ will match entire words, with an optional space in between, which was the original intention. Thanks for the catch.