fizloki
fizloki

Reputation: 151

Regex match of all characters with multiple instances

Using match, I'd like "here" to return [ee], "heree" to return [eee] and "her" to return [null]. Also "heirei" would return [ee,ii].

Assume the string is all letters with no spaces. I imagine it involves some combination of ([\w]) and \1+, but I can't figure it out.

Thanks!

Upvotes: 0

Views: 80

Answers (1)

alpha bravo
alpha bravo

Reputation: 7948

this could be done in two steps
use this pattern (.)(?!.*\1) and replace with nothing Demo
then use the same pattern (.)(?!.*\1)on the result and replace with $1$1Demo
then sort final result

Upvotes: 1

Related Questions