forcing tabs in regex

dark777 jeanzonta777 at yahoo.com.br
Wed Feb 28 01:06:30 UTC 2018


Regex validates years bisexto and not bisextos in format:
const std::regex 
pattern(R"(^(?:(?:(0?[1-9]|1\d|2[0-8])([-/.])(0?[1-9]|1[0-2]|[Jj](?:an|u[nl])|[Mm]a[ry]|[Aa](?:pr|ug)|[Ss]ep|[Oo]ct|[Nn]ov|[Dd]ec|[Ff]eb)|(29|30)([-/.])(0?[13-9]|1[0-2]|[Jj](?:an|u[nl])|[Mm]a[ry]|[Aa](?:pr|ug)|[Ss]ep|[Oo]ct|[Nn]ov|[Dd]ec)|(31)([-/.])(0?[13578]|1[02]|[Jj]an|[Mm]a[ry]|[Jj]ul|[Aa]ug|[Oo]ct|[Dd]ec))(?:\2|\5|\8)(0{2,3}[1-9]|0{1,2}[1-9]\d|0?[1-9]\d{2}|[1-9]\d{3})|(29)([-/.])(0?2|[Ff]eb)\12(\d{1,2}(?:0[48]|[2468][048]|[13579][26])|(?:0?[48]|[13579][26]|[2468][048])00))$)");

this regex above validates the formats through backreferences.

dd-mm-yyyy ou dd-str-yyyy ou dd-Str-yyyy
dd/mm/yyyy ou dd/str/yyyy ou dd/Str/yyyy
dd.mm.yyyy ou dd.str.yyyy ou dd.Str.yyyy



Regex validates years bisexto and not bisextos in format:
const std::regex 
pattern(R"(^(?:\d{4}([-/.])(?:(?:(?:(?:0?[13578]|1[02]|[Jj](?:an|ul)|[Mm]a[ry]|[Aa]ug|[Oo]ct|[Dd]ec)([-/.])(?:0?[1-9]|[1-2][0-9]|3[01]))|(?:(?:0?[469]|11|[Aa]pr|[Jj]un|[Ss]ep|[Nn]ov)([-/.])(?:0?[1-9]|[1-2][0-9]|30))|(?:(0?2|[Ff]eb)([-/.])(?:0?[1-9]|1[0-9]|2[0-8]))))|(?:(?:\d{2}(?:0[48]|[2468][048]|[13579][26]))|(?:(?:[02468][048])|[13579][26])00)([-/.])(0?2|[Ff]eb)([-/.])29)$)");

this regex above had to validate the formats through 
backreferences.

but it is validating in the following formats
yyyy-mm/dd ou yyyy-str/dd ou yyyy-Str/dd
yyyy/mm.dd ou yyyy/str.dd ou yyyy/Str.dd
yyyy.mm-dd ou yyyy.str-dd ou yyyy.Str-dd


when it had to validate only in the following formats
yyyy-mm-dd ou yyyy-str-dd ou yyyy-Str-dd
yyyy/mm/dd ou yyyy/str/dd ou yyyy/Str/dd
yyyy.mm.dd ou yyyy.str.dd ou yyyy.Str.dd

how do I do it validate only with some of the tabs?




More information about the Digitalmars-d-learn mailing list