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

275
Views
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 answers
Answer question

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 Report

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 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!