| Author |
How to add removal of newLine in a regexp pattern
|
Andrew Carney
Ranch Hand
Joined: Oct 17, 2006
Posts: 96
|
|
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
Joined: Oct 13, 2005
Posts: 32654
|
|
|
If I remember correctly, (but you can check here and here) line end characters count as whitespace (\s).
|
 |
Andrew Carney
Ranch Hand
Joined: Oct 17, 2006
Posts: 96
|
|
Uhmmmm so there is no way to around this other than going through each stringbin the splitted array...?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Check out the possible flags for java.util.regex.Pattern. I believe DOTALL is the one you need.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Andrew Carney
Ranch Hand
Joined: Oct 17, 2006
Posts: 96
|
|
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
Joined: Oct 17, 2006
Posts: 96
|
|
|
.
|
 |
 |
|
|
subject: How to add removal of newLine in a regexp pattern
|
|
|