Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
Regex, convert html string to array, issue with languages and and special characters

I am not an expert with regex, and have an issue trying to convert a html string to an array of html elements, so the idea was if we get by example:

Sample String:

<p>Welcome to my awesome website for more info <a href="www.myanotherawesomewebsite.com" target="_blank">click here</a></p> 

(which actually can be any possible combination)

So I wanted to get something like :

'<p>', 'Welcome to my awesome website for more info','<a href="www.myanotherawesomewebsite.com" target="_blank">', 'click here','</a>',</p>'

So this could be achieved with the next regex:

/(<[^>]+>|[a-zè A-Z0-9]+)?/g

So using match function, for testing:

 '<p>Welcome to my awesome website for more info <a href="www.myanotherawesomewebsite.com" target="_blank">click here</a></p>'.match(/(<[^>]+>|[a-zè A-Z0-9]+)?/g)

and this one works, however there is a problem going on with the languages, for everything apart english works okay, but when I have characters in french, or german, this doesn't work anymore...

The work around was to do something like:

/(<[^>]+>|[a-zàâäèéêëîïôœùûüÿçäöüÄÖÜÀÂÄÈÉÊËÎÏÔŒÙÛÜŸÇß!#.?”“«» A-Z0-9\-\u00A0]+)?/g

which works but not 100%, also, not working at all with things like 'sup' or 'sub', etc...

so my question is... there is a way to improve this? Help and advices will be very welcome. Thank you in advance for reading...

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can simply use [^<] for the non-tag node instead of enumeration of characters.
Also, I don't think you need question mark at the end. It would help only if you had an empty string input.

So the result regexp is /(<[^>]+>|[^<]+)/g

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda