c++ - Meta Regex: test if regex is only a string (no regex "wildcards") -
i have (assumed formed) regex expresion r. want test if regex expression single match (all letters, numbers, , escaped expressions) or swapped else. function, "haswildcards", work this:
bool = haswildcards("asdf");//returns false bool b = haswildcards("asdf*");//returns true bool c = haswildcards("asdf[123]");//returns true bool d = haswildcards("asdf\\[123\\]");//returns false
i using boost::regex, if helps @ all. thinking of checking if regex expression matches this:
(^(([\[\^\$\.\|\?\*\+\(\{\}])))?(\\[qedwsdwsbazzb])?([^\\][\[\^\$\.\|\?\*\+\(\)\{\}])?
i've tested on few expressions (using regextest tool of grepwin)
so non-escaped regex symbol start, non-escaped flag,non-escaped regex sumbol in body. there alternative? did screw up? there better way?
well, there's quick two-step way test this. instead of testing escaped characters and wildcards in 1 regex, first line of function remove escaped characters, second line test remaining string wildcard-type expressions.
.*((\[.+?\])|(\{[0-9]*,[0-9]*\})|(\*)|(\+)).*
will match string contains *, +, {#,#}, or [] expression. in function, return whether or not passed string matches expression.
Comments
Post a Comment