Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
RegEx for capturing ticket ID's in a URL

I'm attempting to craft a RegEx that will isolate the ticket ID numbers in my URL and send them back to me in a bug report as seen below.

  const input = document.getElementById('nameInput')
        data = {
          "name": input.value || "Problem with ticket"+ window.location.href.match(/\d/),
          "story_type" : "Bug",
          "description": window.location.href

I have also tried pulling the whole URL

 "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()@:%_\+.~#?&//=]*)/)

However, both return "Problem with ticket Null", I admit I'm terrible at RegEx, so what would be the best way to write this? I've attached an example URL below.

https://xoxoxox.zendesk.com/agent/tickets/2116248
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

If there can be more digits in the url, you can make it specific to get it after tickets in a capture group.

Check first if there is a match, and then get the capture group 1 value:

\/tickets\/(\d+)

Regex demo

let m = "https://xoxoxox.zendesk.com/agent/tickets/2116248".match(/\/tickets\/(\d+)/);
if(m) {
  console.log(m[1]);
}

Output

2116248
about 4 years ago · Juan Pablo Isaza Report

0

If ticket ID is only digits.

"https://xoxoxox.zendesk.com/agent/tickets/2116248".replace(/.*\/(\d*)/,"$1")

Result : 2116248

about 4 years ago · Juan Pablo Isaza Report

0

You can try the following RegEx \d+ for retrieving the required ID,

As demonstrated in the code snippet below,

url = "https://xoxoxox.zendesk.com/agent/tickets/2116248";

let ticketID = url.match(/\d+/);
console.log(ticketID);

Read more about it here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!