javascript - 用于在 URL 中捕获票证 ID 的正则表达式
问题描述
我正在尝试制作一个正则表达式,它将隔离我的 URL 中的票证 ID 号,并在错误报告中将它们发回给我,如下所示。
const input = document.getElementById('nameInput')
data = {
"name": input.value || "Problem with ticket"+ window.location.href.match(/\d/),
"story_type" : "Bug",
"description": window.location.href
我也试过拉整个网址
"Problem with ticket"+ window.location.href.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/)
但是,两者都返回“票空问题”,我承认我在正则表达式方面很糟糕,那么写这个的最好方法是什么?我在下面附上了一个示例 URL。
https://xoxoxox.zendesk.com/agent/tickets/2116248
解决方案
如果票证只有数字。
"https://xoxoxox.zendesk.com/agent/tickets/2116248".replace(/.*\/(\d*)/,"$1")
结果:2116248
推荐阅读
- mysql - 在 Node.js 中同时生成的发票具有相同的编号。如何实现独特性?
- jquery - 如果数据库中存在记录,则执行条件
- python-3.x - 为什么总是“模块'xxx'没有属性'xxx'”?
- bash - 如何在 bash 中并行执行脚本?
- node.js - 在 Windows 上的 package.json 脚本中使用 NODE_PATH 变量
- devise - 将 devise-jwt 添加到 rails api -> 如何在为 JWTBlacklist 生成模型时解决问题?
- algorithm - 生成随机数但排除多个范围而不循环
- javascript - 烧瓶是否支持通过 GET REQUEST 传递的 JSON 编码参数(在正文中)
- c# - c#为Outlook生成ics文件
- selenium-webdriver - 当除innerText之外的所有元素都相同时如何单击按钮