Reputation: 41
I have various strings in the format of .PREFIX-word1-word2-word3
where PREFIX can be any word and there can be 1 or more words that follow the prefix (in this case word1 word2 word3).
What I'm attempting to do is match on any words that follow the prefix so that in the end I get back just the words (in this case word1 word2 word3). Therefore, I don't want to match on .PREFIX
or any dashes.
Given that PREFIX can be anything I've been using (?<=-).*$
which matches word1-word2-word3
.
What am I missing in order to just match on word1 word2 word3
?
Upvotes: 1
Views: 941
Reputation: 163207
You can exclude matching the hyphen using a negated character class starting with [^
(?<=-)[^-]+
If you just want a single word after the hyphen, you can also exclude matching whitespace chars \s
(?<=-)[^-\s]+
Upvotes: 1