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

173
Views
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 answers
Answer question

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 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!