Match regex from right to left?

后端 未结 6 440
心在旅途
心在旅途 2020-12-11 15:27

Is there any way of matching a regex from right to left? What Im looking for is a regex that gets

MODULE WAS INSERTED              EVENT
LOST SIGNAL ON E1/T         


        
6条回答
  •  离开以前
    2020-12-11 15:53

    With regex, you could simply replace this:

    ^.{56}|.{19}$
    

    with the empty string.

    But really, you only need to cut out the string from "position 56" to "string-length - 19" with a substring function. That's easier and much faster than regex.

    Here's an example in JavaScript, other languages work more or less the same:

    var lines = [
      'CLI MUX trap received: (022) CL-B  MCL-2ETH             MODULE WAS INSERTED              EVENT   07-05-2010 12:08:40',
      'CLI MUX trap received: (090) IO-2  ML-1E1        EX1    LOST SIGNAL ON E1/T1 LINK        OFF     04-06-2010 09:58:58',
      'CLI MUX trap received: (094) IO-2  ML-1E1        EX1    CRC ERROR                        EVENT   04-06-2010 09:58:59',
      'CLI MUX trap received: (009)                            CLK IS DIFF FROM MASTER CLK SRC  OFF     07-05-2010 12:07:32'
    ];
    for (var i=0; i

提交回复
热议问题