• Post Reply Bookmark Topic Watch Topic
  • New Topic

Replace sequence of whitespaces by comma  RSS feed

 
Lukas Benberg
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]
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!