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

144
Views
Reemplazo de expresiones regulares entre paréntesis que contienen el mismo tipo de paréntesis en el medio

Estoy tratando de reemplazar la siguiente cadena

 \section{Welcome to $\mathbb{R}^n$} Some content

con

 <h1>Welcome to $\mathbb{R}^n$</h1> Some content

Obviamente, el problema es que tengo aperturas { y } entre las llaves. He intentado usar algo como

 strOutput = strOutput.replace(/\\section\*\s*\{([^}]*)\}/g, "<h1>$1</h1>");

en JavaScript, pero sin suerte. ¿Cómo sigo acercándome a esto?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Aquí hay un ejemplo:

 let str = String.raw`\section{Welcome to $\mathbb{R}^n$}` let result = `<h1>${str.match(/(?<={).*(?=})/)}</h1>` console.log(result)

about 4 years ago · Juan Pablo Isaza Report

0

Qué tal esto:

 let str = String.raw`\section{Welcome to $\mathbb{R}^n$}` let m = str.replace(/\\section\s*\{(.*)}$/g, "$1") let result = `<h1>${m}</h1>` console.log(result)

El problema con su expresión era \* , lo que significa asteriscos literales, ¡pero por lo demás casi lo tiene!

about 4 years ago · Juan Pablo Isaza Report

0

Para el caso de uso del OP de llaves anidadas y no anidadas, se necesita una expresión regular que apunte y capture explícitamente el contenido entre dos llaves (apertura/cierre) que también contiene un par de llaves de apertura/cierre... /\{(?<nested>[^{}]+\{[^{}]+\}[^{}]+)\}/g ...

 const sample = String.raw`\section{Welcome to $\mathbb{R}^n$} \textbf{Other text} \textbf{Other text} \textbf{Other text} \textbf{Other text} \section{Welcome to $\mathbb{R}^n$} \textbf{Other text}\section{Welcome to $\mathbb{R}^n$} \textbf{Other text} \textbf{Other text} \textbf{Other text} \textbf{Other text} \section{Welcome to $\mathbb{R}^n$} \textbf{Other text}`; // see ... [https://regex101.com/r/z4hZUt/1/] const regXNested = /\{(?<nested>[^{}]+\{[^{}]+\}[^{}]+)\}/g; console.log( sample .replace(regXNested, (match, nested) => `<h1>${ nested }</h1>`) )

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!