正则表达式匹配具有唯一(非重复)字符的单词 [英] regex to match a word with unique (non-repeating) characters
本文介绍了正则表达式匹配具有唯一(非重复)字符的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一个正则表达式,它仅在所有字符都是唯一的情况下才匹配一个单词,意思是,单词中的每个字符只出现一次.
I'm looking for a regex that will match a word only if all its characters are unique, meaning, every character in the word appears only once.
示例:abcdefg
-> 将返回 MATCHabcdefgbh
-> 将返回 NO MATCH(因为字母 b
重复多次)
Example:
abcdefg
-> will return MATCH
abcdefgbh
-> will return NO MATCH (because the letter b
repeats more than once)
推荐答案
试试这个,可能有用,
^(?:([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, as many times as possible, 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) «$»
这篇关于正则表达式匹配具有唯一(非重复)字符的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文