aspose file tools*
The moose likes Oracle/OAS and the fly likes Oracle and regular expressions, linefeeds Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "Oracle and regular expressions, linefeeds" Watch "Oracle and regular expressions, linefeeds" New topic
Author

Oracle and regular expressions, linefeeds

D. Ogranos
Ranch Hand

Joined: Feb 02, 2009
Posts: 214
In our oracle db, there is a varchar column in which I want to replace all linefeeds (or carriage return/linefeeds) with "<br/>" (we're changing a textfield for use with a html editor). I looked up the REGEXP_REPLACE function of oracle which seems like it should be able to do that, but I can't seem to get the reg exp right...I tried

REGEXP_REPLACE(column_name, '(\r?\n)', '<br/>')

but I see no replacement being done. I think I got the basic syntax right as I can replace normal characters. I also tried writing the linefeed in different ways, like \\n or \x0a but these don't seem right either. Has anyone done this before perhaps and can tell me the right syntax, documentation I saw says it should be \r and \n but these simply don't work for me
D. Ogranos
Ranch Hand

Joined: Feb 02, 2009
Posts: 214
I solved this differently now, using the normal REPLACE function of oracle:

update <table> set <column>=REPLACE(<column>, CHR(13)) where ...;
update <table> set <column>=REPLACE(<column>, CHR(10), '<br/>') where ...;

First, carriage return characters are removed. Then, linefeed characters are replaced by <br/>. This seems to work fine.

Still interested if anyone knows the correct syntax for a regular expression tho.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Oracle and regular expressions, linefeeds
 
Similar Threads
regarding line break
how to replace eol and nl
innerHTML questions etc.
Line break in Excel thru Java
Retaining paragraph breaks from text