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) «$»
3条答案
按热度按时间gmxoilav1#
试试这个,可能有用,
解释
xfyts7mz2#
您可以检查字符串中是否有2个字符示例:
(我只是简单地抓取其中一个字符,然后检查它是否在其他地方有一个带有反向引用的副本。其余的
.*
是不关心)。如果上面的正则表达式匹配,则字符串具有重复字符。如果上面的正则表达式不匹配,则所有字符都是唯一的。
上面正则表达式的优点是正则表达式引擎不支持环顾四周。
显然,john woo的解决方案是一种直接检查唯一性的漂亮方法。它在每个字符处Assert前面的字符串不包含当前字符。
35g0bw713#
这一个也将提供与任何长度的单词完全匹配的非重复字母:
不久前,我对@bohemian提供的另一个问题的答案进行了轻微修改,以得到这个答案。
上面的问题也提出了一段时间了,但我认为在这里也有这个正则表达式模式会很好。