Regular expression in Relace : Replacement character 'New Line'
How can I use a 'New Line' Character as the replacement String(/Character) in the Replace operator?
Background:
I need to elminiate empty lines from an attribute.
So, replace multiple consecutive 'New Lines' by one 'New Line'.
My search so far is
(?s)((\n*)(\n))
which locates those multple empty lines, with an replacement string of '$3' .
I could have used also a simple '\n{2,}'.
But regardsless of what I do I can get a 'new Line' (or any other special character) as an replacement string.
Neither '\n' or '\013' worked. (Also not '\t' for test purposes.)
I have read through http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html already, but there is nothing related to replacement strings an any limitations.
Any ideas appreciated.
Best Answer
-
kludikovsky Member Posts: 30 Maven
Solution:
New Line <> New Line !
Instead of just using the NL ('\n') the '\r\n' has to be used.
'\n' oder the \x0D od LF character is actually used in the a 'Create Document' - 'Document to Data' sequenece, while in my impoerted data from disk this where the \r\n-sequence for line end.
So the '((\r\n)(\r\n)*)' will find those multiple New Lines. which can be replaced by the $2.
1
Answers
hello @kludikovsky - yes I have encountered this many times before. To my knowledge there is not a good replace function that replaces regex with more regex. What I do is a workaround using encode/decode URL:
Scott
huh! Well glad you found a solution as well!
Scott