Regex expression for "string x / 0 / y"

Hello everybody,

I am trying to find a resolution for a regex expression:

I want to have something like this

"string x / 0 / y", where x is in the range between 1-6 and y is in the range between 1-48

I tried this:

interface GigabitEthernet [1-6]/0/([1-4]*[1-8])

but then if y = 50, it still takes 5, and "0" falls

I tried this

interface GigabitEthernet [1-6]/0/([1-4][1-8])

but then, if y = 1-9, it does not match the expression.

I would appreciate any help with this.

Thank!

+3
source share
7 answers

Try ([1-9]|[1-3][0-9]|4[0-8])for the second part of your regular expression.

, , . /(\d+)/0/(\d+)/, , .

+4

. . , :

(\d)/0/(\d{1,2})

, , ,

x >= 1 and x <= 6

-

y >= 1 and y <= 48

, .


Python :

s = "5/0/14"
m = re.match(r"(\d)/0/(\d{1,2})", s)
if m is not None:
    x = int(m.group(1))
    y = int(m.group(2))
    if x >= 1 and x <= 6 and y >= 1 and y >= 48 then
        print("Looks good!")
+4

:

interface GigabitEthernet [1-6]/0/([1-9]|[1-3][0-9]|4[0-8])
+1

Regex , . , :

interface GigabitEthernet [1-6]/0/([1-3][0-9]|4[0-8]|[1-9])$

interface GigabitEthernet [1-6]/0/([1-3][0-9]|4[0-8]|[1-9](?![0-9]))

, .

+1

([1-9]|[1-3][0-9]|4[0-8]). , , , .. .

([1-3][0-9]?|4[0-8]?|[5-9]) . , , .

+1

-

[1-6]/0/([1-9] | [1-3] [0-9] | 4 [0-8])

0

GigabitEthernet [1-6]/0/((4 [0-8]) | ([1-3]?\d))

. 39 40-48

0
source

Source: https://habr.com/ru/post/1772017/


All Articles