我如何去除被包裹在冒号之间的东西并检索它的最后一个

How would I strip something from being encased between colons and retrieve the last one on it

我一直在不知疲倦地研究这个 pcap 分析脚本,终于找到了“某个地方”,但现在我遇到了从用冒号包裹的行中剥离协议的问题:

IE:

eth:ethertype:arp

eth:ethertype:ip:tcp:ssh

我正在尝试从 ssharp 中获取每个对象的最后一个值,这些对象的大小发生变化(使用 tshark pcap - JSON 文件)

有多种方法可以做到这一点。您可以使用 .split(":") 然后从结果数组中取出最后一项。

let str = "eth:ethertype:ip:tcp:ssh";

let splits = str.split(":");
console.log(splits[splits.length - 1]);

您可以使用如下正则表达式:

let str = "eth:ethertype:ip:tcp:ssh";
let regex = /:([^:]+)$/;
let matches = str.match(regex);
if (matches) {
    console.log(matches[1]);
} else {
    console.log("no matches");
}