Regexp_replace help

Hi,
I am writing a regexp_replace and I am a newbie to this concept. I am looking for help to convert the following pattern as follows:
If I see a pattern of two lowercase followed by a period and a space, then I need to convert the pattern to two lowercase followed by a period and a new line character.
"lowercaselowercaseperiodspace" --> "lowercaselowercaseperiodnewline"
Any help would be appreciated.
Ajay

Hi,
[[:lower:]]or (depending on your NLS settings)
[a-z]means a lower-case letter, so if newline is CHR (10) on your system, you can say:
REGEXP_REPLACE ( str
            , '([[:lower:]]{2}\.) '
            , '\1' || CHR (10)
            )When writing or debugging regular expressions, you may want to be excruciatingly clear about what you're doing, like this:
REGEXP_REPLACE ( str
            , '('               || -- \1 is ...
                 '[[:lower:]]{2}'     || --       any 2 lower-case letters
              '\.               || --         followed by a dot
           ')'               || -- end \1
           ' '                  -- followed by a space
            , '\1'                || -- \1 is copied without changes
              CHR (10)             -- but the space is replaced by newline
            )Edited by: Frank Kulash on Mar 7, 2011 2:56 PM

Similar Messages

  • Reposting for Regexp_Replace Help

    We're facing a roadblock that none of us can seem to work through. If you're a RegExp expert your help is very much in need and appreciated!
    Here's my SQL:
    1 SELECT regexp_replace(wrk_clob, 'href=\s*"([^"]+)"',
    2 || '\1' || ':'
    3 || get_id_list(in_table, in_state, '\1')
    4 INTO wrk_clob
    5 FROM dual;
    I am passing in a CLOB, scrubbing it with Regexp_Replace (line 1) , taking the piece that's been scrubbed out and displaying it (line 2), and using that scrubbed piece of data in a FUNCTION call to get other data for display (line 3).
    Actually, that's what we want it to do. However, I can display the scrubbed piece of data on line 2 but I CAN'T seem to use that piece of data in my FUNCTION call (get_id_list(in_table, in_state, '\1').
    Can anyone tell me why I can see it on line two but can't use it in line 3? Is there some kind of alternative approach?
    Thanks!

    I do apologize for the misunderstanding!
    Implementing your suggestion I ran into an issue with buffer sizes. As you'll recall I stated the FUNCTION to which I need to pass this value had a SPEC as follows:
    FUNCTION get_id_list(
    in_table VARCHAR2,
    in_state VARCHAR2,
    in_doc_name VARCHAR2)
    RETURN VARCHAR;
    I get an ORA-22835: Buffer too small for CLOB to CHAR. I surround the function call with DBMS_LOB.SUBSTR and it won't capture the value!
    Here's the code with the dbms_lob.substr:
    FUNCTION testswap(      in_table VARCHAR2,
                             in_state VARCHAR2,
                             in_clob CLOB )
                                  RETURN CLOB
    IS
              wrk_clob          CLOB                     := in_clob;
              v_match               CLOB;
    BEGIN
    SELECT regexp_replace(wrk_clob, 'href=\s*"([^"]+)"',
                        in_table || ':'
                        || get_id_list(in_table, in_state, DBMS_LOB.SUBSTR(regexp_replace(wrk_clob, '^.*?href=\s*"([^"]+)".*$','\1'), 4000,1))
    INTO wrk_clob
    FROM dual;
         RETURN wrk_clob;
    END testswap;

  • Help with Regular Expressions and regexp_replace

    Oh great Oracle Guru can I can gets some help
    I need to clean up the phone numbers that have been entered in Oracle eBusiness per_phones table. Some of the phone numbers have dashes, some have spaces and some have char. I would just like to take all the digits out and then re-format the number.
    Ex.
    914-123-1234 .. output (914) 123-1234
    9141231234 ..again (914) 123-1234
    914 123 1234 .. (914) 123-1234
    myphone ... just null
    (914)-123-1234.. (914) 123-1234
    I really tried to understand the regular expressions statments, but for some reason I just can't understand it.

    Hi,
    Welcome to the forum!
    I would create a user-defined function for this. I expect there will be a lot of exceptions to the regular rules (for example, strings that do not contain exactly 10 digits, such as '1-800-987-6543') that can be handled, but would require lots of nested fucntions and othwer complicted code if you had to do it in a single statement.
    If you really want to do it with a regular expression:
    SELECT     phone_txt
    ,     REGEXP_REPLACE ( phone_txt
                     , '^\D*'          || -- 0 or more non-digits at the beginning of the string
                           '(\d\d\d)'     || -- \1 = 3 consecutive digits
                    '\D*'          || -- 0 or more non-digits
                           '(\d\d\d)'     || -- \2 = 3 consecutive digits
                    '\D*'          || -- 0 or more non-digits
                           '(\d\d\d)'     || -- \3 = 4 consecutive digits
                    '\D*$'             -- 0 or more non-digits at the end of the string
                     , '(\1) \2-\3'
                     )          AS new_phone_txt
    FROM    table_x
    ;

  • Help me about built-in functions like regexp_substr,regexp_replace

    Hi everybody
    Can anyone help me to understand these functions like regexp_substr,regexp_replace ...
    Will be better if documantation include examples with different situations or it may be links
    Thx

    also - if you're just trying to learn regular expressions - which are generic and very much not specific to oracle, there are plenty of tutorial websites around the place that you'll find by googling.
    well worth learning, regardless of the programming language you're working with.

  • Help with REGEXP_REPLACE

    Hello Experts
    I am having trouble in parsing the address as below. Please see the desired results part.
    Please help in solving this issue. I am trying the REGEXP_REPLACE but could not get the sucess.
    The Oracle version I am working on is
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Thanks
    RB
    with table1 as
    *(select '1805SOUTHETHELAVE' addr1 from dual union all*
    select '1165MCALLISTERRD' addr1 from dual union all
    select '2161COMMERCCDR APT206' addr1 from dual union all
    select '1048HARPERLEEDR' addr1 from dual union all
    select '20021NWCR4290' addr1 from dual
    looking for SOLUTION AS
    *1805 SOUTHETHEL AVE*
    *1165 MCALLISTER RD*
    *2161 COMMERCC DR*
    *1048 HARPERLEE DR*
    *20021 NWCR 4290*

    Rb2000rb65 wrote:
    Hello Experts
    I am having trouble in parsing the address as below. Please see the desired results part.
    Please help in solving this issue. I am trying the REGEXP_REPLACE but could not get the sucess.This sounds like homework so I am not going to post the exact solution I came up with but will explain how I I did it. I was able to obtain results like yours with a single complex query.
    >
    The Oracle version I am working on is
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    with table1 as
    *(select '1805SOUTHETHELAVE' addr1 from dual union all*
    select '1165MCALLISTERRD' addr1 from dual union all
    select '2161COMMERCCDR APT206' addr1 from dual union all
    select '1048HARPERLEEDR' addr1 from dual union all
    select '20021NWCR4290' addr1 from dual
    looking for SOLUTION AS
    *1805 SOUTHETHEL AVE*
    *1165 MCALLISTER RD*
    *2161 COMMERCC DR*
    *1048 HARPERLEE DR*
    *20021 NWCR 4290*I was unable to do this in one statement due to the inconsistent pattern you presented. An easy pattern was
    numbers text AVE or RD or DR or numbers
    Removing the apartment number was harder, which I solved by doing the replacements in 2 passes with an inline view using the logic
    select regexp_replace(first_result),'pattern','replacemant_pattern')
    from (select regexp_replace(column,'pattern','replacement_pattern') as first_result
    I used the \d (digit) and \D (non-digit) pattern keys for matching something like '\d+' to match digits (the + matches 1 or more) and '\D+' for non-digits, encosing the matched text in () for patterns later. The replacement strings I used were '\1 \2 \3' for the first replacement with the matched text followed by a space and a match against the text 'APT ' followed by a number replaced with a null to remove it. The first (inner) match looked something like '(+number with 1 or more matches+)((+string with 1 or more matches+)(AVE or DR or RD).
    I hope this helps :)
    Edited by: riedelme on Feb 13, 2013 10:02 AM
    Frank and I posted at about the same time. His answer is better

  • Need help with regexp_replace

    Hi,
    Can somebody help me out? I am trying to find a regexp for the following pattern?
    In my document, here is the pattern that I would like to remove.
    <<snip>>
    * [16]News
    * [17]Sport
    * [18]Leisure
    * [19]Info
    * [20]You Say
    * [21]Family
    * [22]Video
    * [23]Announcements
    * [24]Advertise
    * [25]Buy/Sell
    * [26]Click2Find
    * [27]Dating
    * [28]Cars
    * [29]Homes
    * [30]Jobs
    <<snip>>
    Thanks
    Ajay

    Useful also to see text you don't want to match. Depending on how general/specific you want it to be, whether there are always two digits, or just one or more, whether you only want to match those specific words, or just any text up to a new line in the text:
    SELECT REGEXP_REPLACE('HELLO* [16]News
    * [17]Sport
    * [18]Leisure
    * [19]Info
    * [20]You Say
    * [21]Family
    * [22]Video
    * [23]Announcements
    * [24]Advertise
    * [25]Buy/Sell
    * [26]Click2Find
    * [27]Dating
    * [28]Cars
    * [29]Homes
    * [30]Jobs
    WORLD','\* \[\d+\].+') FROM DUAL
    SELECT REGEXP_REPLACE('HELLO* [16]News
    * [17]Sport
    * [18]Leisure
    * [19]Info
    * [20]You Say
    * [21]Family
    * [22]Video
    * [23]Announcements
    * [24]Advertise
    * [25]Buy/Sell
    * [26]Click2Find
    * [27]Dating
    * [28]Cars
    * [29]Homes
    * [30]Jobs
    WORLD','\* \[\d{2}\](News|Sport|Leisure|Info|You Say|Family|Video|Announcements|Advertise|Buy/Sell|Click2Find|Dating|Cars|Homes|Jobs)') FROM DUAL

  • Help Needed to add Hyphen in REGEXP_REPLACE

    Hi All,
    I need a help to add hyphen in my select criteria so that it does not filter the hypen.
    I am using below REGEXP_REPLACE to get my output, everything is fine now except the Hyphen (-) character is not recognized.
    select REGEXP_REPLACE('abcd-efgh123{}$(),', '[^[a-z,A-Z,0-9,(,),{,},_,$,.,'',[:space:]]]*','') from dual;
    Can you please help?
    Thanks

    The hyphen has a special meaning inside a regular expression. You can use if you make clear that the extended meaning is not possible in this case.
    example
    with testdata as (select 'A-C' txt from dual union all
                      select 'X-12' txt from dual union all
                      select '1''2' txt from dual union all
                      select 'ab#' txt from dual union all
                      select '()' txt from dual union all
                      select 'a b*~' txt from dual union all
                      select 'ab' txt from dual union all
                      select 'abcd-efgh123{}$(),'  txt from dual
    select txt
          ,REGEXP_REPLACE(txt, '[^[a-zA-Z0-9(){}_$.''[:space:]-]]*','') keep_chars
          ,REGEXP_REPLACE(txt, '[[a-zA-Z0-9(){}_$.''[:space:]-]]*','') remove_chars
    from testdata;
    TXT     KEEP_CHARS     REMOVE_CHARS
    A-C     A-C     
    X-12     X-12     
    1'2     1'2     
    ab#     ab     #
    a b*~     a b     *~
    ab     ab     
    abcd-efgh123{}$(),     abcd-efgh123{}$()     ,I removed the comas. In case you want that char also to be removed just add it somewhere. It is not used as a separator in this specific case.

  • Help with REGEXP_REPLACE upper replacement string

    Hi All,
    I am attempting to uppercase the replacement string from my reg expression without success:
    SELECT regexp_replace('src=/i/uie_v2/js','(/uie_v2/)',upper('\1')) from dual
    returns 'src=/i/uie_v2/js'
    I understand that upper cannot be used .. just showing as an example. Any ideas on how to achieve this ?
    Thanks in advance :)
    Greg

    >
    I need a way of using a search pattern that goes from the first double quote to the last slashThis can be achieved as below
    SQL> select str,regexp_substr(str,'"/([^"]*?/){1,}',1) res
      2  from testdata;
    STR                                                     RES
    <link rel="stylesheet" type="text/css" href="/i/uie_V2/ "/i/uie_V2/ext-3.0.0/resources/css/
    ext-3.0.0/resources/css/ext-all-uie.css">
    <script src="/i/uiE_v2/js/bob/bobsFile.js"></script>
    <script src="/i/UIE_v2/js/fred/fredsFile.js"></script>
    <script src="/i/uiE_v2/js/john/johnsFile.js"></script>
    <link rel="stylesheet" type="text/css" href="/i/uie_V2/ "/i/uie_V2/ext-3.0.0/resources/css/
    ext-3.0.0/resources/css/ext-all-uie.css">
    <script src="/i/uiE_v2/js/bob/bobsFile.js"></script>
    <script src="/i/UIE_v2/js/fred/fredsFile.js"></script>
    <script src="/i/uiE_v2/js/john/johnsFile.js"></script>For achieving yor replace, can we use PL/SQL as below?
    I think the same thing can be achieved using CONNECT BY..SYS_CONNECT_BY_PATH or Recursion. But PL/SQL seems to be better.
    And we can wait for a MODEL solution..
    SQL> create or replace function f1(p_str varchar2) return varchar2 is
      2    lc_str varchar2(4000) := p_str;
      3    ln_count number := 1;
      4  begin
      5    while regexp_substr(lc_str,'"/([^"]*?/){1,}',ln_count) is not null loop
      6      lc_str := regexp_replace(lc_str,'"/([^"]*?/){1,}',
      7          lower(regexp_substr(lc_str,'"/([^"]*?/){1,}',1,ln_count)),1,ln_count);
      8      ln_count := ln_count + 1;
      9    end loop;
    10    return lc_str;
    11  end f1;
    12  /
    Function created.
    SQL> select str,f1(str) res
      2  from testdata;
    STR                                                     RES
    <link rel="stylesheet" type="text/css" href="/i/uie_V2/ <link rel="stylesheet" type="text/css" href="/i/uie_v2/
    ext-3.0.0/resources/css/ext-all-uie.css">               ext-3.0.0/resources/css/ext-all-uie.css">
    <script src="/i/uiE_v2/js/bob/bobsFile.js"></script>    <script src="/i/uie_v2/js/bob/bobsFile.js"></script>
    <script src="/i/UIE_v2/js/fred/fredsFile.js"></script>  <script src="/i/uie_v2/js/fred/fredsFile.js"></script>
    <script src="/i/uiE_v2/js/john/johnsFile.js"></script>  <script src="/i/uie_v2/js/john/johnsFile.js"></script>
    <link rel="stylesheet" type="text/css" href="/i/uie_V2/ <link rel="stylesheet" type="text/css" href="/i/uie_v2/
    ext-3.0.0/resources/css/ext-all-uie.css">               ext-3.0.0/resources/css/ext-all-uie.css">
    <script src="/i/uiE_v2/js/bob/bobsFile.js"></script>    <script src="/i/uie_v2/js/bob/bobsFile.js"></script>
    <script src="/i/UIE_v2/js/fred/fredsFile.js"></script>  <script src="/i/uie_v2/js/fred/fredsFile.js"></script>
    <script src="/i/uiE_v2/js/john/johnsFile.js"></script>  <script src="/i/uie_v2/js/john/johnsFile.js"></script>Edited by: jeneesh on Oct 5, 2012 9:37 AM
    Not rigorously tested

  • Help in using  regexp_replace function.

    Hi everyone,
    i have a string something like this..
    varchar2(100) := 'SUBF1.AAAAAAAAAAAAA.SUBF1.BBBBBBBBBB.SUBF1'
    i want to replace the FIRST OCCURANCE of SUBF1 with some other string.
    EX:
    For the above string if i replace the FIRST OCCURANCE of SUBF1 with 'Hi' the output gonna be like this
    OUTPUT : 'Hi.AAAAAAAAAAAAA.SUBF1.BBBBBBBBBB.SUBF1'
    Sorry if this question had asked previously in this FORUM.
    Thanks in advance..
    phani

    test@ora>
    test@ora>
    test@ora> --
    test@ora> with t as (
      2    select 'SUBF1.AAAAAAAAAAAAA.SUBF1.BBBBBBBBBB.SUBF1' as x from dual)
      3  --
      4  select x,
      5         regexp_replace(x,'SUBF1','Hi',1,1) as modx
      6  from t;
    X                                          MODX
    SUBF1.AAAAAAAAAAAAA.SUBF1.BBBBBBBBBB.SUBF1 Hi.AAAAAAAAAAAAA.SUBF1.BBBBBBBBBB.SUBF1
    1 row selected.
    test@ora>
    test@ora>isotope

  • Regexp_replace? help plz

    Hi all,
    I recieve a VARCHAR2 string, which can basically contain enything alpha numeric also special characters and spaces.
    At the moment i use a bunch of functions which replaces certain things, trim spaces.
    I basically want to use regexp_replace to simply remove any spaces and spacial characters (commas, back/forward slashes, ambersands e,t,c) and just take the alpha numeric data.
    It takes their ID, then concatenates the first two letters of there lastname, then first two letters of firtname then firdt two letters of middle name.. any missing characters get padded with *.
    This is the code i have at the moment
       declare
       rms_id NUMBER := 4767;
       last_name VARCHAR2(10) := 'fds dgdg';
       first_name VARCHAR2(10) := 'tu/  yu rt';
       middle_name VARCHAR2(10) := '';
       answer VARCHAR2(20);
       BEGIN
       SELECT rms_id || rpad(lower(substr(replace(nvl(last_name,'**'),' ',''),1,2)),2,'*') ||
                                rpad(lower(substr(replace(nvl(first_name,'**'),' ',''),1,2)),2,'*') ||
                                rpad(lower(substr(replace(nvl(middle_name,'**'),' ',''),1,2)),2,'*')
                                INTO answer
       FROM dual;
       dbms_output.put_line(answer);
       END;

    Thanks for the reply.
    So basically what i want from this is:
    rms_id ||
    first two letters of last_name ||
    first two letter of first_name ||
    first two letters of middle_name
    if there is no middle_name for example then I want '**' to be put in place of it. And that is the same for all the three names.
    If the middle name is just 'e', then i want the output of middle_name to equate to 'e*'.
    So the answer would basically be somethig like
    4767bame**
    with t as (select 4767 as rms_id, 'batmaz' as last_name, 'mehmet' as first_name, '' as middle_name from dual)
    But some names contain special characters so i wanted those removed and spaces trimmed.
    I hope i Havant confused the situation lol

  • Query help in regular expression Query

    Hi all,
    Version details
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE     11.1.0.7.0     Production
    TNS for 32-bit Windows: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - ProductionI have table RULE with one column as CLOB data type and my requirement is as follows
    Sample Data :
    0-7IfFlowControl0.-7dd670afb-2d41-440f-958d-c19f0f75e91dareErrorsPostedAtHeader(00760)ClaimErrorCollection0.-7-1000FlowControl0-8ThenFlowControl0.-8a0c1c903-0c04-4d68-b5a8-10cbd4a03e9faddRequiredElementErrors(00760 & D)
    Expected Output .
    00760
    00760
    D
    I want the values within braces() and when ever there is an & symbol inside braces then i want it in the next row.
    Please see the above example .Any help in this regard is would be highly appreciated ...........
    Thanks,
    P Prakash
    Edited by: prakash on Nov 10, 2011 9:19 PM

    with t
    as
    select '0-7IfFlowControl0.-7dd670afb-2d41-440f-958d-c19f0f75e91dareErrorsPostedAtHeader(00760)ClaimErrorCollection0.-7-1000FlowControl0-8ThenFlowControl0.-8a0c1c903-0c04-4d68-b5a8-10cbd4a03e9faddRequiredElementErrors(00760 & D)' str
      from dual
    ), t1
    as
    select replace(replace(regexp_substr(str, '\([^)]*\)', 1, level),')'), '(') str
      from t
    connect by level <= regexp_count(str, '\([^)]*\)')
    select regexp_substr(str, '[^&]+', 1, t2.l)
      from t1
    cross join
             select level l
               from (
                      select max(length(regexp_replace(str, '[^&]')))+1 cnt
                        from t1
            connect by level <= cnt
           ) t2
    where regexp_substr(str, '[^&]+', 1, t2.l) is not null

  • Please help with regular expression

    Hello,
    With the help of my previous posting answers, Re: Procedure to Extract multiple substring from a string , I updated the query. But, I am not getting desired answer in all case. Could you please help me out? My query is based on the previous posting. Any other simple way to achieve this?
    I will really appreciate it.
    select
           ltrim ( regexp_substr(txt, '\[(\w+)', 1, level), '[')      as id, /* id is number */
           ltrim ( regexp_substr(ltrim ( regexp_substr(txt, ':[^]]+', 1, level), ':'), '\w+-*\d*', 1, 1), ':')  as qid, /* Qid could be char/number/space any combination except ':' */
           ltrim ( regexp_substr(ltrim ( regexp_substr(txt, ':[^]]+', 1, level), ':'), '\w+', 1, 2), ':')      as num,
          to_date( ltrim ( regexp_substr(ltrim ( regexp_substr(txt, ':[^]]+', 1, level), ':'), '[^:]+', 1, 3), ':'),'MM/DD/YY')   as effdate
    from  (
                            select  '[10946:M100:N:][10947:Q1222:N:][38198:PPP-2:N:][13935:PPP-6:N:][38244:QQQ-4:Y:01/01/10]'     as txt
                            from     dual
            connect by level <= length(regexp_replace(txt, '[^[]'));I should get :
    ID             QID          NUM         EFFDATE
    10946     M100     N     
    10947     Q1222     N     
    38198     PPP-2     N     
    13935     PPP-6     N     
    38244     QQQ-4     Y     01-JAN-10But, getting
    ID             QID          NUM          EFFDATE
    10946     M100     N     
    10947     Q1222     N     
    38198     PPP-2     2     
    13935     PPP-6     6     
    38244     QQQ-4     4     01-JAN-10Thanks,

    Hi,
    So the num column is wrong, is that it?
    Describe what the num column should be. For example "num is the 3rd part of the :-delimited list enclosed in the square brackets".
    If that's what you want, then change the definition of num from
    ...                     ltrim ( regexp_substr(ltrim ( regexp_substr(txt, ':[^]]+', 1, level), ':'), '\w+', 1, 2), ':')      as num,to
    ...                      REGEXP_SUBSTR  ( REGEXP_SUBSTR ( txt
                                          , '[^]]+'
                                                , 1
                                       , LEVEL
                             , '[^:]+'
                             , 1
                             , 3
                             )       AS num,

  • Help needed in Regular Expression

    I have been give a task to replace all table_name (Emp) in Procedure p1 to Table_name(Employee).
    Can anyone help me ?
    Regards,
    Prathamesh

    Hi, Prathamesh,
    REGEXP_REPLACE ( txt
                , '(^|\W)emp(\W|$)'
                , \1employee\2'
                )will return a copy of txt with the full word 'emp' replaced by 'employee'.
    For example, if txt is:
    emp foo a=emp  temp emp_name emp.bthe expression above will return
    employee foo a=employee  temp emp_name employee.b 
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statments) and the results you want from that data.

  • Help need in masking

    Hi,
    we had requirement for our cilent. One of column there numbers which lengths of the rows are :16,9 and 12 etc
    ex:
    12345-78910-11223-- he wants like this 12345-XXXXX-11223
    123-4567-8910-- he wants like this 123-XXXX-8910
    All the numbers which generated are dynamic. He wants us to mask the middle numbers.
    The middle numbers like come in different fashion like above some time for 3 numbers and some times its 5 and 4. there are around 1 million records.
    We tried to develop but this is not working for entire rows
    we took like this
    select substr(<<colname>>,'-',1,1), substr(<<col>>,'-',1,2) from <<tabble>>;
    But this is working for 1st row and the rest of the rows are missing.
    Could any one help to resolve the issue
    Thanks & Regards
    pallis
    Edited by: pallis on Jul 20, 2011 11:29 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    you can do this:
    SQL> with test as
      2  (select '12345-78910-11223' str from dual union all
      3   select '123-4567-8910'str from dual
      4  )
      5  select str
      6       , regexp_replace (str, '-[[:digit:]]+-', '-xxxxx-') str
      7    from test
      8  /
    STR                       STR
    12345-78910-11223         12345-xxxxx-11223
    123-4567-8910             123-xxxxx-8910
    2 rows selected.the key thing there is
    regexp_replace (str, '-[[:digit:]]+-', '-xxxxx-')Edited by: Alex Nuijten on Jul 20, 2011 8:11 PM

  • Help needed in sql

    Hi,
    I am getting the filename as below and i want to extract some part of the string with the filename and the output need as below
    FileName : THE_PK_SOURCE_CLASS0002_PKID5403_20130603_342342.txt 
    Output:
    ======
    5403-THE_PK_SOURCE_CLASS0002_PKID5403
    Please help me in advance
    Thx,

    That's easy. Just mark the last two parts asa optional ({0,2})
    with data as (
    select 'THE_PK_SOURCE_CLASS0002_PKID5403_20130603_342342.txt' str from dual
    union all
    select '20130712-v1-THE_PK_SOURCE_CLASS0002_PKID5403_20130603_342342.txt' from dual
    union all
    select '20130712-v1-THE_PK_SOURCE_CLASS0002_PKID5403_1222.txt' from dual
    union all
    select '20130712-v1-THE_PK_SOURCE_CLASS0002_PKID5403.txt' from dual
    union all
    select '20130712-v1-THE_PK_SOURCE_CLASS0002_PKID5403_132.txt' from dual
    union all
    select '20130712-v1-THE_PK_SOURCE_CLASS0002_PKID5403_20130603_342342.txt' from dual
    select
    -- all from the start to and including the last hyphen is cut off
    regexp_replace(str, '^(.+-)?([^-]+?)(\d+)(_\d+){0,2}\.txt$', '\3-\2\3') str
    from data
    from data
    STR
    5403-THE_PK_SOURCE_CLASS0002_PKID5403
    5403-THE_PK_SOURCE_CLASS0002_PKID5403
    5403-THE_PK_SOURCE_CLASS0002_PKID5403
    5403-THE_PK_SOURCE_CLASS0002_PKID5403
    5403-THE_PK_SOURCE_CLASS0002_PKID5403
    5403-THE_PK_SOURCE_CLASS0002_PKID5403
    Message was edited by: chris227 Changed to the simplified version, but it's the same for the "corrected" veriosn too.

Maybe you are looking for

  • Jdeveloper error while running a page

    Hi All, I am using 10.1.3.3.0.3 Jdev. I am trying to run a page using Jdev but I am getting below error. I can run the tutorial page successfully but when I try to run other page then it gives me error. I am trying to run below page- /oracle/apps/icx

  • Update current date in mysql using Update form DW CS4 PHP

    I have a field called datePosted that is set to curdate in the database.  What I want to do is when the checkbox on this form called approved is checked, and the form is submitted, I want that dateApproved field to update to the current date in the d

  • Graphics in Language Translation

    Platform: WinXP 64-bit / Adobe CS5 Design Premium Hi, Is there a preferred method for handling graphics (and leaders/callouts) in InDesign for language translation? And while I'm at it, ditto for content reuse. I realize that translation & single-sou

  • Error starting wiki server in Mac Mini server with Mountain Lion 10.8.3

    Hi, i've got a problem with my wiki server. The service doesn't start! It does an error while i try to start the wiki! The service can't read the service impostation! How can i solve it?? Anyone with the same problem?? Thanks!

  • Teststand New Thread VS LabVIEW "Call & Forget" Asynchronous call

    Hi everyone, Here is an example taken from the ni.com website showing how to use LabVIEW to post a TestStand Notifier.  I have modified the example to fit the situation I needed to use it for.  I have an example which works fine (When I use a TestSta