Это регулярное выражение соответствует abcbcabc , но не 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»
Редактировать
как было объяснено в комментариях, границы строк do имеют значение. Регулярное выражение затем становится
\m(?:(\w)(?!\1))+\M
Слава Гамбо.