user690182
user690182

Reputation: 279

Tcl: match string only if it is followed by a number [regex]

Given that I have the following output :

Loopback1 is up, line protocol is up 
  Hardware is Loopback
  Description: ** NA4-ISIS-MGMT-LOOPBACK1_MPLS **
  Internet address is 84.116.226.27/32
  MTU 1514 bytes, BW 8000000 Kbit, DLY 5000 usec, 
     reliability 255/255, txload 1/255, rxload 1/255
  Encapsulation LOOPBACK, loopback not set
  Keepalive set (10 sec)
  Last input 12w3d, output never, output hang never
  Last clearing of "show interface" counters never
  Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
  Queueing strategy: fifo
  Output queue: 0/0 (size/max)
  5 minute input rate 0 bits/sec, 0 packets/sec
  5 minute output rate 0 bits/sec, 0 packets/sec
     0 packets input, 0 bytes, 0 no buffer
     Received 0 broadcasts (0 IP multicasts)
     0 runts, 0 giants, 0 throttles
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
     6 packets output, 456 bytes, 0 underruns
     0 output errors, 0 collisions, 0 interface resets
     0 output buffer failures, 0 output buffers swapped out

How can I match "Loopback1" and not "Loopback" ? In other words, how can I match the interface name only if there is a number next to it, in Tcl ?

Upvotes: 0

Views: 737

Answers (1)

pogo
pogo

Reputation: 1550

use lookahead

Loopback(?=\d+)

It matches only Loopback in Loopback followed by any number of digits. If you want to match loopback and the number, useLoopback\d+

Upvotes: 3

Related Questions