gpt4 book ai didi

正则表达式匹配具有唯一(非重复)字符的单词

转载 作者:行者123 更新时间:2023-12-03 12:02:35 25 4
gpt4 key购买 nike

我正在寻找一个正则表达式,它只在所有字符都是唯一的情况下才匹配一个单词,意思是,单词中的每个字符只出现一次。

示例 :abcdefg -> 将返回 匹配 abcdefgbh -> 将返回 没有匹配项 (因为字母 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, 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) «$»

关于正则表达式匹配具有唯一(非重复)字符的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12870489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com