Regular Expression for Range (2-16)

后端 未结 5 2015
臣服心动
臣服心动 2021-02-05 06:45

I want to match a number between 2-16, spanning 1 digit to 2 digits.

Regular-Expressions.info has examples for 1 or 2 digit ranges, but not something that spans both:

5条回答
  •  生来不讨喜
    2021-02-05 07:17

    Use the python package regex_engine for generate regular expressions for numerical ranges

    You can install this package by using pip

    pip install regex-engine

    from regex_engine import generator
    
    generate = generator()
    
    regex = generate.numerical_range(2,16)
    
    print(regex)
    

    ^([2-9]|1[0-6])$

    You can also generate regexes for floating point and negative ranges

    from regex_engine import generator
    
    generate = generator()
    
    regex1 = generate.numerical_range(5,89)
    regex2 = generate.numerical_range(81.78,250.23)
    regex3 = generate.numerical_range(-65,12)
    

提交回复
热议问题