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

281
Visualizações
Using JavaScript Regex to replace some content I get a Unmatched ')' Regex error

I'm moving a large blog from WordPress to another platform, and I am trying to re-create WordPress shortcodes with Javascript. I've been able to write the Regex to replace [youtube]'s shortcodes without problems, but I'm having problems with [soundcloud]'s.

The format of the shortcode is the following:

[soundcloud url=”http://api.soundcloud.com/tracks/33660734”]

I created the following Regex rule, that seems to work on Regex 101

\[soundcloud url="http(s?):\/\/api\.soundcloud\.com\/tracks\/([a-zA-Z0-9]*)"(\s*?)\] https://regex101.com/r/JKL45q/2

But when I include it in my script:

{
      service: 'soundcloud',
      regex: new RegExp('\[soundcloud url="http(s?):\/\/api\.soundcloud\.com\/tracks\/([a-zA-Z0-9]*)"(\s*?)\]', 'ig'),
},

I get this error, which I can't understand:

main.js:29 Uncaught SyntaxError: Invalid regular expression: /[soundcloud url="http(s?)://api.soundcloud.com/tracks/([a-zA-Z0-9]*)"(s*?)]/: Unmatched ')' (at main.js:29:14)
    at new RegExp (<anonymous>)
    at main.js:29:14
    at main.js:142:3

The source script is here:
https://hotmc.pages.dev/assets/js/main.js

This is a page where the error occurs in the console:
https://hotmc.pages.dev/2011/01/10/esclusivo-anteprima-album-micha-soul-un-brano-in-free-download

Can anyone help? I found other questions about this error, but haven't been able to apply the suggested fixes.

Thank you in advance, S.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I think you can remove the () of the ([a-zA-Z0-9]*)

new RegExp('[soundcloud url="http(s?):\/\/api\.soundcloud\.com\/tracks\/[a-zA-Z0-9]*"(\s*?)]', 'ig').test(`[soundcloud url="http://api.soundcloud.com/tracks/33660734"]`)
about 4 years ago · Juan Pablo Isaza Relatório

0

I have been able to get rid of the error by changing hot the RegExp object is initialized.

From this:

new RegExp('\[soundcloud url="http(s?):\/\/api\.soundcloud\.com\/tracks\/([a-zA-Z0-9]*)"(\s*?)\]', 'ig')

To this:

new RegExp(/\[soundcloud url="http(s?):\/\/api\.soundcloud\.com\/tracks\/([a-zA-Z0-9]*)"(\s*?)\]/, 'ig')

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