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

187
Views
Regex está fallando para algunas URL

Tengo un Regex como /url\s*\((?!['("]?(?:data):)['"]?([^')"\)]*)['"]?([\)]|$)/gi donde lo estamos usando para analizar la etiqueta de estilo para obtener la URL (por ejemplo, imagen de fondo). Falla para URL como

1] background-image: url(\2f content\2f dam\2f dx\2fus\2f en\2f error-pages\2f 404-1440x612_edge2.jpg\2fjcr%3acontent\2frenditions\2f cq5dam.tablet_1400.1400.595.jpg); background-position: 50% 50%;

debe ser => url(\2f content\2f dam\2f dx\2fus\2f en\2f error-pages\2f 404-1440x612_edge2.jpg\2fjcr%3acontent\2frenditions\2f cq5dam.tablet_1400.1400.595.jpg)

2] imagen de fondo: url("https://www.investopedia.com/thmb/m3EwtlYfbUhlr9e34AofFj9wok8=/1300x0/filters:contrast(10):brightness(-10):no_upscale()/TopTerms-2bdc464d466944deb41fc07379407600.jpeg")

debería ser => url("https://www.investopedia.com/thmb/m3EwtlYfbUhlr9e34AofFj9wok8=/1300x0/filters:contrast(10):brightness(-10):no_upscale()/TopTerms-2bdc464d466944deb41fc07379407600.jpeg")

Falla en contraste (10): ya que considera el corchete de cierre de contraste (10) como el final de la URL.

3] background-image:url('https://cdn.comcast.com/-/media/Images/www_xfinity_com/TV/X1/09072021 Refresh/10X1HeroDesktop.png?rev=d04c61c0-3658-457d-8260-74ef6694c0ed&mw=1280&mh=600&hash=6A1C4FEC8499EE38864BA31D24B9E42220D8C7EB')" background-size: cover;

debería ser => url('https://cdn.comcast.com/-/media/Images/www_xfinity_com/TV/X1/09072021 Refresh/10X1HeroDesktop.png?rev=d04c61c0-3658-457d-8260-74ef6694c0ed&mw=1280&mh=600&hash=6A1C4FEC8499EE38864BA31D24B9E42220D8C7EB')

4] style="position:absolute; background:transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=) repeat 0 0"

debe ser => url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=)

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

0

Podrías usar una alternancia | para obtener los diferentes formatos.

 url\s*\((?:data:image\S+|(['"]).*?\1|[^()]*)\)

En partes, el patrón coincide:

  • url\s*\( Coincidir con url, espacios en blanco opcionales y (
  • (?: Grupo de no captura para la alternancia
    • data:image\S+ Match data:image y 1+ caracteres que no son de espacio en blanco
    • | O
    • (['"]).*?\1 Coincidencia desde la cotización de apertura hasta la cotización de cierre
    • | O
    • [^()]* Coincidencia 0+ veces cualquier carácter excepto paréntesis
  • ) Cerrar grupo de no captura
  • \) Partido )

Demostración de expresiones regulares

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!