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

148
Vistas
Handle slicing and formatting strings with regex and Vue

I have an issue when code vue, with string:

しらべよう、まとめよう ≪A≫[B]きものの ≪C≫[D]≪E≫[F]

I need processing to be able to render something like this:

the text above will be the text inside []. then the bottom will start with the letter inside ≪≫, and finally the remaining letter.

...(if have)
 <ruby>B
   <rt>A</rt>
 </ruby>
... (if have)
<ruby>D
 <rt>C</rt>
</ruby>
... (if have)

https://codepen.io/AkiraGosho/pen/NWaNNrZ?editors=1111

This is my demo, but I only got 1 letter, so I don't know how to satisfy the problem

Thank you very much.

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

0

You can do this using .replace, here is an example:

const input = 'しらべよう、まとめよう ≪A≫[B]きものの ≪C≫[D]≪E≫[F]'
const output = input.replace(/([^≪]*)≪(.)≫[^\[]*\[(.)\]/g, '$1\n<ruby>$3\n\t<rt>$2</rt>\n</ruby>\n');
console.log(output);

What this does, is to use a regex that splits the input into groups, the first group ([^≪]*) selects any character that is not a ≪ fallowed by ≪, then, the second group (.) selects a character preceded by ≪ and fallowed by ≫. The third group uses the same logic but instead of using ≪ and ≫, it uses [ and ].

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