c++ - irc channel regex composition -


i'm having trouble composing regex string irc channel

// digit      =  %x30-39                 ; 0-9 static const std::string digit("(?:[\x30-\x39])"); // channelid  = 5( %x41-5a / digit )   ; 5( a-z / 0-9 ) static const std::string channelid("(?:(?:[\x41-\x5a]|" + digit + "){5})"); // chanstring =  %x01-07 / %x08-09 / %x0b-0c / %x0e-1f / %x21-2b / %x2d - 39 / %x3b - ff static const std::string chanstring("(?:[\x01-\x07\x08-\x09\x0b-\x0c\x0e-\x1f\x21-\x2b\x2d-\x39\x3b-\xff])"); // channel    =  ( "#" / "+" / ( "!" channelid ) / "&" ) chanstring [":" chanstring] static const std::string channel("(?:(?:[#+&]|(?:!" + channelid + "))" + chanstring + "(?::" + chanstring + ")?)"); 

i'm digit , channelid formed.

const std::regex digit(dapps::regex::digit); assert(std::regex_match("0", digit)); assert(std::regex_match("1", digit)); assert(std::regex_match("2", digit)); assert(std::regex_match("3", digit)); assert(std::regex_match("4", digit)); assert(std::regex_match("5", digit)); assert(std::regex_match("6", digit)); assert(std::regex_match("7", digit)); assert(std::regex_match("8", digit)); assert(std::regex_match("9", digit)); assert(!std::regex_match("10", digit));  const std::regex channelid(dapps::regex::channelid); assert(std::regex_match("abcde", channelid)); assert(std::regex_match("12345", channelid)); 

and i'm pretty sure chanstring formed well, why doesn't work?

const std::regex channel(dapps::regex:: channel); assert(std::regex_match("#channelname", channel)); 

the problem chanstring matches strings of length 1. it's regex [^\x00\x07\x0d\x0a ,:], needs {n}, *, or + @ end match more 1 character.

unfortunately, doesn't seem issue in code. rfc 2812's abnf defines grammar (trimming unused syntaxes):

channel    =  ( "#" / "+" / ( "!" channelid ) / "&" ) chanstring               [ ":" chanstring ] chanstring =  %x01-07 / %x08-09 / %x0b-0c / %x0e-1f / %x21-2b chanstring =/ %x2d-39 / %x3b-ff                 ; octet except nul, bell, cr, lf, " ", "," , ":" channelid  = 5( %x41-5a / digit )   ; 5( a-z / 0-9 ) 

that grammar definition makes chanstring match strings of length 1. should have defined chanstring 1*44(...), or similar.

to work around issue, you'll either have create beastly, unwieldy regex (for example, like this) or manually check channel's length make sure doesn't exceed valid limits (50, say) before validating regex.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -