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

235
Visualizações
Invalid regular expression - invalid group

I have a regex that doesn't work on my website, but whenever I tried to use it on jsfiddle it works. My goal was to get the URLs existing in a sentence.

const regex = /\b(?:(?:https?\:\/\/|\b)(?:(?:\d{1,3}\.){3}\d{1,3}|(?<![\@\.])(?:[^\s\/\?\#\@\.]+\.){1,2}[a-z]{2,3})(?:[\/\#\:\?][^\s\@]*|\b)(?![\@\.]))/gm;

Here is the error that I'm getting:

SyntaxError: Invalid regular expression: /\b(?:(?:https?\:\/\/|\b)(?:(?:\d{1,3}\.){3}\d{1,3}|(?<![\@\.])(?:[^\s\/\?\#\@\.]+\.){1,2}[a-z]{2,3})(?:[\/\#\:\?][^\s\@]*|\b)(?![\@\.]))/: Invalid group
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Use the "best regex trick ever", consume emails first, then capture your pattern matches.

Here is a way to extract the URLs:

const regex = /\S+@\S+|\b((?:https?:\/\/)?(?:(?:\d{1,3}\.){3}\d{1,3}|(?:[^\s\/?#@.]+\.){1,2}[a-z]{2,3})(?:[\/#:?][^\s@]*|\b))(?![@.])/g;
let result = [], m;
const text = "Visit http://lalala.la or contact lala@lalala.la";
while(m=regex.exec(text)) {
  if (m[1] !== undefined) result.push(m[1]);
}
console.log(result);

See the regex demo.

The \S+@\S+| part matches one or more non-whitespace chars, @ and again one or more non-whitespace chars, so the rest of the pattern can match in any other context. The code only returns Group 1 matches if any (note the capturing parentheses around the second alternative).

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