Sublime Forum

(little)? regular expression hitch ... variable field on the output side

#1

Hi all,

I have a little problem - hopefully just a little on - and maybe you guys can help me there. I need a regular expression that generates this result:

Input

13: br-eth4:     mac 94:57:a5:51:cf:0f 
14: bond0:     mac 94:57:a5:51:cf:0c 
15: br-bond0:     mac 94:57:a5:51:cf:0c     inet 100.99.2.67/27 br-bond0
16: bond2:     mac 3c:fd:fe:9d:02:19 
17: bond1:     mac 3c:fd:fe:9d:02:2c 
290: tapf13149d2-f7:     mac b6:34:56:72:95:2a 
312: tap8b7a9959-7d:     mac 0e:86:c0:d4:d6:71 
321: tapb3d33379-43:     mac 02:c4:37:b6:34:7c 
65: tap8e3df1fe-73:     mac 6a:5b:48:81:45:9f 
322: tapbee658e5-c9:     mac 9a:02:b4:9f:6f:9c 

Intented output:

13: br-eth4:           mac 94:57:a5:51:cf:0f 
14: bond0:             mac 94:57:a5:51:cf:0c 
15: br-bond0:          mac 94:57:a5:51:cf:0c     inet 100.99.2.67/27 br-bond0
16: bond2:             mac 3c:fd:fe:9d:02:19 
17: bond1:             mac 3c:fd:fe:9d:02:2c 
290: tapf13149d2-f7:   mac b6:34:56:72:95:2a 
312: tap8b7a9959-7d:   mac 0e:86:c0:d4:d6:71 
321: tapb3d33379-43:   mac 02:c4:37:b6:34:7c 
65: tap8e3df1fe-73:    mac 6a:5b:48:81:45:9f 
322: tapbee658e5-c9:   mac 9a:02:b4:9f:6f:9c 

I have no trouble with recognizing the number and string fields. My only trouble is to handle the variable length of white spaces in the output. Input side is always four white spaces, but output is the problem.

0 Likes

#2

regex replacements aren’t really suitable for column alignment - you’re probably better off using a plugin like
https://packagecontrol.io/packages/AlignTab

0 Likes

#3

I’m pretty sure that it is possible. Regular expressions are really really powerful. U can do I think anything with it. The problem is that they are hard to understand when it gets complex.

In the meantime I figured out a resolution for this little tricky riddle. But unfortunately it is a two step solution.

First step: Blow up the white space field from 5 to 30.

Input      ^(\d+: +[^ ]+:) {5}(mac.+)$
Output:    $1                              $2

Second step: Catch 30 characters from start of line and from ‘mac’ till end of line.

Input      ^(.{30}) +(mac.+)$
Output:    $1$2

It would be much cooler to have it in just one step

0 Likes