You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何提取字符串中第二个冒号(:)之后的全部内容?

提取第二个冒号后的字符串内容

Python 实现

通过字符串分割并拼接剩余部分:

s = "1:723:NVDA:NSDQ::Z4189274321:Snapshot Report:10:COMPUTER & TECHNOLOGY:241:Semiconductor"
# 分割前两个冒号,取第三个及之后的部分重新用冒号连接
result = ":".join(s.split(":", 2)[2:])
print(result)

输出结果:

NVDA:NSDQ::Z4189274321:Snapshot Report:10:COMPUTER & TECHNOLOGY:241:Semiconductor

Bash 脚本实现

用cut命令直接截取第3个字段及之后的内容:

s="1:723:NVDA:NSDQ::Z4189274321:Snapshot Report:10:COMPUTER & TECHNOLOGY:241:Semiconductor"
echo "$s" | cut -d ":" -f 3-

执行后直接输出目标字符串。

JavaScript 实现

分割法

const s = "1:723:NVDA:NSDQ::Z4189274321:Snapshot Report:10:COMPUTER & TECHNOLOGY:241:Semiconductor";
const parts = s.split(":", 3);
const result = parts[2];
console.log(result);

正则匹配法

const s = "1:723:NVDA:NSDQ::Z4189274321:Snapshot Report:10:COMPUTER & TECHNOLOGY:241:Semiconductor";
const regex = /^[^:]+:[^:]+:(.*)$/;
const match = s.match(regex);
const result = match ? match[1] : "";
console.log(result);

通用正则表达式方案

适用于所有支持正则的编程语言,匹配规则:

^[^:]+:[^:]+:(.*)$
  • ^[^:]+:匹配开头到第一个冒号前的内容
  • :[^:]+:匹配第一个冒号到第二个冒号前的内容
  • :(.*)$:匹配第二个冒号到结尾的所有内容,捕获组1即为目标结果

内容的提问来源于stack exchange,提问作者Landon Statis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 04:03:15