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

249
Views
¿Cómo reemplazar la URL con el ancla, excepto la URL de YouTube?

Estoy escribiendo una función que verifica los enlaces HTTP y los reemplaza con etiquetas de anclaje si existen. Si hay una URL de YouTube, la reemplaza con un iframe. Tengo problemas para terminarlo porque no sé cómo agregar un ancla para esas URL que no son URL de YouTube.

Aquí están las funciones

 export const renderLinkWithText = (text = '') => { // eslint-disable-next-line const replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim const newText = text.replace(replacePattern1, '<a class="anchor_link" target="_blank" href="$1">$1</a> ') return newText.replace(/\n\r?/g, '<br />').replace(/(?:https:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?.*v=)?(\w+)/g, '<iframe width="100%" height="350px" src="https://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>') }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Le gustaría incluir una anticipación negativa en su primer patrón con el que excluir las URL de YouTube. Algo del estilo de:

 (?!(www.)?(youtube\.com|youtu\.be))

El patrón completo se convertiría en:

 (\b(https?|ftp):\/\/(?!(www.)?(youtube\.com|youtu\.be))[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])

Editar: he corregido la respuesta inicial, prueba tus expresiones regulares en línea. https://regex101.com/ para uno acepta lo anterior.

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!