How avoid replacement of new line char in regex string replacement?
Maulin Vasavada
Ranch Hand
Joined: Nov 04, 2001
Posts: 1865
posted
0
Hi all,
I have the following code,
Here the problem is, "\\s+" pattern matches the newlines in the string and replace them with TOKEN. I want every multiple occurance of whitespace chars to be replaced by TOKEN except for newline chars. How can I do that via some regex pattern only?
Alternatively I have to go long way to, 1. first replace all new line with a known token- say TOKEN1 to prevent them from getting replaced via "\\s+" pattern matching. 2. then match "\\s+" pattern and replace all multiple whitespace occurances with single space 3. replace all TOKEN1 back to newline.
Is there any other way via regex pattern we can do this? OR I have to go this long way I mention above?