• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add removal of newLine in a regexp pattern

 
Andrew Carney
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a long String coming from a different system that I am escaping using regexp using:



i.e. reserve only alphanumeric and white spaces.
The problem is that I still get the \n in the splitted array and I would like to remove it.
I can do a replaceAll("\\n", "") on each String in the array however would really prefer to do it in the original pattern before the split.

Any ideas...?

 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I remember correctly, (but you can check here and here) line end characters count as whitespace (\s).
 
Andrew Carney
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uhmmmm so there is no way to around this other than going through each stringbin the splitted array...?
 
Rob Spoor
Sheriff
Pie
Posts: 20546
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the possible flags for java.util.regex.Pattern. I believe DOTALL is the one you need.
 
Andrew Carney
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DOTALL flag did the trick, thanks!
I thought that since I am not using the dot in my regexp then it will have no effect but I guess it does
 
Andrew Carney
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic