Thursday, 15 March 2012

c# - What am I doing wrong with this regular expression? -



c# - What am I doing wrong with this regular expression? -

(?!^\*)\w{1,20}

i'm trying ensure input between 1 , 20 characters long , doesn't begin '*'. other character under sun allowed though.

the look doesn't work in c# seem work using tester:http://www.regexplanet.com/advanced/java/index.html

what need change?

thanks insight on this.

edit: request, here c# code:

system.text.regularexpressions.regex tempregex = new system.text.regularexpressions.regex(@"(?!^\*)\w{1,20}"); homecoming tempregex.ismatch(_inputstring);

not sure trying first capturezero-width negative lookahead assertion, next regular look seem match requirement:

@"^[^\*]\w{0,19}$"

"^...$" portion forces matching of whole string. first character "[^\*]" (anything star) counted against [1-20] restriction, range {0,19}.

c# regex

No comments:

Post a Comment