1

I can't get my head around how regular expressions are done and am trying to get a replace statement to work with one.

I am trying to put a space around everything but numbers and decimals

mathEquation = mathEquation.replaceAll("\\D(?!$)", " 0ドル ");

That works with everything other than numbers but it still adds spaces around decimals (since the \\D includes decimals). I don't know how to exclude the decimals from the search / replace though.

If someone could help me create the regex I'm looking for or lead me towards the answer I'd appreciate it.

Thanks if you reply.

dee-see
24.1k6 gold badges64 silver badges93 bronze badges
asked Mar 28, 2012 at 22:59

1 Answer 1

3

Try this:

mathEquation = mathEquation.replaceAll("[^\\d.](?!$)", " 0ドル "); 

I added a character class for not digits or dot.

answered Mar 28, 2012 at 23:02
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.