6.7. Numbers Within a Certain Range - Regular Expressions ...
文章推薦指數: 80 %
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
延伸文章資訊
- 1Regex Numeric Range Generator — Regex Tools — 3Widgets
Generate regular expressions for numeric ranges. Just enter start and end of the range and get a ...
- 2Regex for Numbers and Number Range (With Examples)
- 3regex - Why doesn't [01-12] range work as expected?
Your goal is evidently to specify a number range: any number between 01 and 12 written with two d...
- 4Regex Numeric Range Generator - Measure Marketer
RegEx Range Generator Tool. RegEx skills are extremely important for people who work on Google An...
- 5Example: Matching Numeric Ranges with a Regular Expression
The regex [0-9] matches single-digit numbers 0 to 9. [1-9][0-9] matches double-digit numbers 10 t...