Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Regular Expression for replacing Leading Spaces

BluShadowOct 16 2006 — edited Oct 17 2006
I don't claim to be any expert on Regular Expressions and even after reading CD's introduction to Reg Exp, I still can't figure out this one which I'm sure must be very basic.

I want to replace all the leading spaces in a string with "." chrs. I could do this using the common replace/substr/instr functions, but I reckoned it would be possible in a single regular regexp_replace call.

So far I've got this...
SQL> select regexp_replace('      FRED BLOGS    WAS HERE    ', '^([:space:])*', '.')
  2  as result
  3  from dual;

RESULT
---------------------------------
.      FRED BLOGS    WAS HERE

SQL>
Which is replacing the start of line with a "." and not the spaces.

But I want my result to be:-
RESULT
---------------------------------
......FRED BLOGS    WAS HERE

SQL>
Cheers
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 14 2006
Added on Oct 16 2006
18 comments
2,620 views