• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Replace sequence of whitespaces by comma

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I need some help with regex. I would like to replace any sequence of whitespaces larger than 5 by comma.

I would like to create a comma seperated file from the following file, where values are delimited by a sequence of whitespaces > 5 (it is a console output). However, single whitespaces may also occur inside the values.




Thanks for your help!

[edit]Add code tags which show the whitespace better.[/edit]
 
Sheriff
Posts: 21787
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the Javadoc of java.util.regex.Pattern. Then tell us which regex you have created for finding 5 or more spaces. Hint: you can use space in regexes without needing to escape it. For instance, " *" is zero or more spaces.
 
Lukas Benberg
Ranch Hand
Posts: 45
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob,
I solved it. My solution is:



Seems to work. I found the Javadoc not very helpful. But here is a good tutorial which I find more helpful for regex beginners: http://www.vogella.de/articles/JavaRegularExpressions/article.html

Regards,
L
 
Do not threaten THIS beaver! Not even with this tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!