This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Oracle and regular expressions, linefeeds