Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda