Regular expression for inconsistent characters
4 answers
This regex matches abcbcabc but not aabbcc
// (?:(\w)(?!\1))+
//
// Match the regular expression below «(?:(\w)(?!\1))+»
// Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
// Match the regular expression below and capture its match into backreference number 1 «(\w)»
// Match a single character that is a "word character" (letters, digits, etc.) «\w»
// Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!\1)»
// Match the same text as most recently matched by capturing group number 1 «\1»
Edit
as explained in the comments, do line boundaries are important . Then the regex becomes
\m(?:(\w)(?!\1))+\M
Kudos to Gumbo.
+4
a source to share