微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

正则表达式将字词与唯一(不重复)字符进行匹配

我正在寻找一个正则表达式,只有当它的所有字符都是唯一的,这意味着该单词中的每个字符才会出现一次。

例:
abcdefg – >将返回MATCH
abcdefgbh – >将返回NO MATCH(因为字母b重复多次)

尝试这个,可能会工作,
^(?:([A-Za-z])(?!.*\1))*$

说明

Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
Match the regular expression below «(?:([A-Z])(?!.*\1))*»
   Between zero 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 «([A-Z])»
      Match a single character in the range between “A” and “Z” «[A-Z]»
   Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!.*\1)»
      Match any single character that is not a line break character «.*»
         Between zero and unlimited times,giving back as needed (greedy) «*»
      Match the same text as most recently matched by capturing group number 1 «\1»
Assert position at the end of a line (at the end of the string or before a line break character) «$»

原文地址:https://www.jb51.cc/regex/357349.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐