• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to remove all non-alphanumeric characters from a string expect decimal point in Java

Resolved: How to remove all non-alphanumeric characters from a string expect decimal point in Java

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Having this String with decimal point, I would like to remove all non alphaNumeric expect the decimal point.
Currently I get "the. book cost 7.55 dollars.";
However I would like to return "the book cost 7.55 dollars";

Answer:

You can use:
RegEx Demo
RegEx Details:
  • (?<!\\d): Previous character is not a digit
  • \\.: Match a dot
  • (?!\\d): Next character is not a digit
  • |: OR
  • [^a-zA-Z\\d. ]+: Match 1+ of non-alphanumeric characters that are not space or dot
  • .replaceAll("\\h{2,}", " "): is for replacing 2+ whitespaces with a single space

If you have better answer, please add a comment about this, thank you!

decimal java regex
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Shopware 400 Status Error “This value is too long. It should have 255 character or less.” When I Try Updating Database Table

01/04/2023

Resolved: Using AWK to count multiple patterns in a file

01/04/2023

Resolved: significance letter above bar graphic in wrong order

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.