regex detects if a character appears in the same string only once

Here are two expressions for negative and positive checks:

  • Matching a string that has no @handles or has at least two: /^(?!.*@\w)|@\w.*@\w/ – see proof
  • Matching a string that only has one @handle: /^(?!.*@\w.*@\w).*@\w/ – see proof.

I think your @handle must be @ + a word character, not a single @.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top