Mateusz Kawka
Mateusz Kawka

Reputation: 422

Regular expression to match string composed entirely of unique characters

I try write a regExp ==> unique character

Like that:

'mam' => false 2*m
'man' => true all unique
'lull' => false

PS. I want regExp, no function.

Upvotes: 0

Views: 457

Answers (1)

user557597
user557597

Reputation:

I'd just test the string outright for true or false

function isNotDup(str) {
  return str.match(/^(?:(.)(?!.*?\1))+$/) ? true : false;
}

console.log('mam = ' + isNotDup('mam'));
console.log('man = ' + isNotDup('man'));
console.log('lull = '   + isNotDup('lull'));
console.log('112233abcabccba = ' + isNotDup('112233abcabccba'));

Upvotes: 2

Related Questions