对不起,我从自己的库中生成了这个,它使用对 Dart/Javascript/Java/Python 有效的语法,但无论如何,这里是:
(?:^)(?:(?:[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKlMNOPQRSTUVWXYZ0123456789]){1,1})(?!(?:(?:(?:(?:_\.){1,1}))|(?:(?:(?:__){1,1}))|(?:(?:(?:\.\.){1,1}))))(?:(?:(?:(?:[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKlMNOPQRSTUVWXYZ0123456789._]){1,1})(?!(?:(?:(?:(?:_\.){1,1}))|(?:(?:(?:__){1,1}))|(?:(?:(?:\.\.){1,1}))))){6,18})(?:(?:[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKlMNOPQRSTUVWXYZ0123456789]){1,1})(?:$)
我的图书馆代码:
var alphaNumeric = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "l", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
var allValidCharacters = new List.from(alphaNumeric);
allValidCharacters.addAll([".", "_"]);
var invalidSequence = (r) => r
.eitherString("_.")
.orString("__")
.orString("..");
var regex = new RegExpBuilder()
.start()
.exactly(1).from(alphaNumeric).notBehind(invalidSequence)
.min(6).max(18).like((r) => r.exactly(1).from(allValidCharacters).notBehind(invalidSequence))
.exactly(1).from(alphaNumeric)
.end()
.getRegExp();
我的图书馆:https ://github.com/thebinarysearchtree/RegExpBuilder