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

使用正则表达式从指定路径提取标识符0068Y00001Sn4P6QAJ

提取路径中Opportunity标识符的正则方法

核心思路

目标标识符始终位于/Opportunity/与/view之间,可利用正则的断言或捕获组特性精准提取这段不含斜杠的字符串。

方案1:正向/反向断言(直接匹配目标内容)

正则表达式:

(?<=\/Opportunity\/)[^\/]+(?=\/view)
  • (?<=\/Opportunity\/):反向肯定断言,确保匹配内容前是/Opportunity/
  • [^\/]+:匹配任意数量的非斜杠字符,刚好对应目标标识符(Salesforce记录ID不含斜杠)
  • (?=\/view):正向肯定断言,确保匹配内容后是/view

方案2:捕获组(匹配整体后提取分组)

如果你的工具支持捕获组,用这个更直观:

\/Opportunity\/([^\/]+)\/view
  • 整个表达式匹配包含目标ID的完整片段
  • ([^\/]+)是第1个捕获组,提取该组内容即可得到目标标识符

代码示例(Python)

import re

path = "/lightning/r/Opportunity/0068Y00001Sn4P6QAJ/view"

# 断言方式提取
match = re.search(r'(?<=\/Opportunity\/)[^\/]+(?=\/view)', path)
if match:
    print(match.group())  # 输出: 0068Y00001Sn4P6QAJ

# 捕获组方式提取
match = re.search(r'\/Opportunity\/([^\/]+)\/view', path)
if match:
    print(match.group(1))  # 输出: 0068Y00001Sn4P6QAJ

内容的提问来源于stack exchange,提问作者Marina Dutta

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 05:36:04