Если вы не хотите, чтобы специальный символ повторялся в вашей полной строке. Вы можете использовать match
и Set
let nonRepeated = (str) => {
let match = str.match(/[.,]/g) || []
let setMatch = new Set(match)
return match.length != setMatch.size
}
console.log(nonRepeated('sometext . something'))
console.log(nonRepeated('sometext,, something . some. some,'))
И если вы не хотите иметь последовательный специальный символ, вы можете использовать его как-то так:
let nonRepeated = (str) => !/([,.])(?=\1)/.test(str)
console.log(nonRepeated('sometext . something'))
console.log(nonRepeated('sometext,, something . some. some,'))