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

177
Vistas
How to replace special characters and numbers with the character and spaces on each side

So basically I'm trying to convert this string: "(1+2) / 2" to this "( 1 + 2 ) / 2". And I've tried this:

String inputInfix = input.replaceAll("[^0-9/]", " [^0-9/] ");

But it doesn't work, is there some way to replace every character except "/" and the digits with a space on either side. For example, "(1 / 2)" -> " ( 1 / 2 )"

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can use

input.replaceAll("(?<=[^\\s/])(?=[^\\s/])", " ")

See the regex demo. Details:

  • (?<=[^\s/]) - a positive lookbehind that matches a location that is immediately preceded with a char other than a whitespace char and a slash
  • (?=[^\s/]) - a positive lookahead that matches a location that is immediately followed with a char other than a whitespace char and a slash.
over 4 years ago · Santiago Trujillo 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