6.7. Numbers Within a Certain Range - Regular Expressions ...

文章推薦指數: 80 %
投票人數:10人

You want to match an integer number within a certain range of numbers. You want the regular expression to specify the range accurately, rather than just ... Skiptomaincontent RegularExpressionsCookbook,2ndEditionbyJanGoyvaerts,StevenLevithan GetfullaccesstoRegularExpressionsCookbook,2ndEditionand60K+othertitles,withfree10-daytrialofO'Reilly. There'salsoliveonlineevents,interactivecontent,certificationprepmaterials,andmore. Startyourfreetrial 6.7. NumbersWithinaCertainRangeProblemYouwanttomatchanintegernumberwithinacertainrange ofnumbers.Youwanttheregularexpressiontospecifytherange accurately,ratherthanjustlimitingthenumberofdigits.Solution1to12(hourormonth):^(1[0-2]|[1-9])$Regexoptions: NoneRegexflavors:.NET, Java,JavaScript,PCRE,Perl,Python,Ruby1to24(hour):^(2[0-4]|1[0-9]|[1-9])$Regexoptions: NoneRegexflavors:.NET, Java,JavaScript,PCRE,Perl,Python,Ruby1to31(dayofthemonth):^(3[01]|[12][0-9]|[1-9])$Regexoptions: NoneRegexflavors:.NET, Java,JavaScript,PCRE,Perl,Python,Ruby1to53(weekoftheyear):^(5[0-3]|[1-4][0-9]|[1-9])$Regexoptions: NoneRegexflavors:.NET, Java,JavaScript,PCRE,Perl,Python,Ruby0to59(minuteorsecond):^[1-5]?[0-9]$Regexoptions: NoneRegexflavors:.NET, Java,JavaScript,PCRE,Perl,Python,Ruby0to100(percentage):^(100|[1-9]?[0-9])$Regexoptions: NoneRegexflavors:.NET, Java,JavaScript,PCRE,Perl,Python,Ruby1to100:^(100|[1-9][0-9]?)$Regexoptions: NoneRegexflavors:.NET, Java,JavaScript,PCRE,Perl,Python,Ruby32to126(printableASCIIcodes):^(12[0-6]|1[01][0-9]|[4-9][0-9]|3[2-9])$Regexoptions: NoneRegexflavors:.NET, Java,JavaScript,PCRE,Perl,Python,Ruby0to127(nonnegativesignedbyte):^(12[0-7]|1[01][0-9]|[1-9]?[0-9])$Regexoptions: NoneRegexflavors:.NET, Java,JavaScript,PCRE,Perl,Python,Ruby–128to127(signedbyte):^(12[0-7]|1[01][0-9]|[1-9]?[0-9]|-(12[0-8]|1[01][0-9]|[1-9]?[0-9]))$... GetRegularExpressionsCookbook,2ndEditionnowwiththeO’Reillylearningplatform. O’Reillymembersexperienceliveonlinetraining,plusbooks,videos,anddigitalcontentfromnearly200publishers. Startyourfreetrial Don’tleaveempty-handed GetMarkRichards’sSoftwareArchitecturePatternsebooktobetterunderstandhowtodesigncomponents—andhowtheyshouldinteract. It’syours,free. Getitnow Close



請為這篇文章評分?