Changeparticular the characters of a string using regular expressions...

Hi all
I'm writing a function using the function of expression regular oracles REGEXP_REPLACE but I could not succeed until now.

My problem is as follows, I have a text in a column say "Scott Sdfdfs Sdfd" I want to replace all the s and S with X characters and make the text looks like "XdfXdf XdfdfX Xdfd".

It is possible by using regular expressions in oracle?
Can you give me some clue?

Thank you
select
  regexp_replace('sdfsdf Sdfdfs Sdfd',
                 's|S', 'X') Replaced
from dual;
REPLACED
------------------
XdfXdf XdfdfX Xdfd 

Tags: Database

Similar Questions

  • How to capture multiple line String using regular expressions?

    Hello

    I have a simple program like this:

    What I want to accomplish is to capture everything between > start and > to end with a single regular expression matching node. It seems that the definition of multiples? true or False does not help.

    I'm using LabVIEW 2012.

    If it is impossible to capture using a single node, that's fine. But I want to assure you that I can make full use of this node without combining several others.

    Thank you!

    > start([\w\s]*) > end

    A point matches any character except line break characters.  You have two of them.

  • Operation of string using regular expressions

    SQL> with raw_data as
      2  (
      3      select 1 id ,'A11P75 P76 R01       U01 U12 U40 U42 V53 VL VR A11' str from dual union all
      4      select 2,'A11P75 P76 R01       U01 U12 U40 U42 V53 VL VR' str from dual union all
      5       select 3,'A11P75 P76 R01       U01 U12 U40 U42 V53 VL  A11 VR' str from dual union all
      6      select 4,'A11P75 P76 R01       U01 U12 U40 U42 V53 A11 VL VR' str from dual union all
      7      select 5,'P75 P76 R01  A11     U01 U12 U40 A11 U42 V53 VL VR ' str from dual
      8  )
      9  select id
     10            ,str
     11            ,case when instr(replace(substr(str,instr(str,' ',-1,3)),'A11','#'),'#')>1
     12                      then replace(str,' A11','')
     13                      else str
     14             end Expected
     15    from raw_data
     16    /
    
    
            ID STR                                                 EXPECTED
    ---------- --------------------------------------------------- ---------------------------------------------------
             1 A11P75 P76 R01       U01 U12 U40 U42 V53 VL VR A11  A11P75 P76 R01       U01 U12 U40 U42 V53 VL VR
             2 A11P75 P76 R01       U01 U12 U40 U42 V53 VL VR      A11P75 P76 R01       U01 U12 U40 U42 V53 VL VR
             3 A11P75 P76 R01       U01 U12 U40 U42 V53 VL  A11 VR A11P75 P76 R01       U01 U12 U40 U42 V53 VL  VR
             4 A11P75 P76 R01       U01 U12 U40 U42 V53 A11 VL VR  A11P75 P76 R01       U01 U12 U40 U42 V53 VL VR
             5 P75 P76 R01  A11     U01 U12 U40 A11 U42 V53 VL VR  P75 P76 R01  A11     U01 U12 U40 A11 U42 V53 VL VR
    
    
    SQL>
    
    
    

    Logic of waiting: there will be a WORD like here "A11" who is looking within the chain

    If this word found in the last three words separated by space, delete this letter as a guide / appearing in the column PROVIDED

    First of all, your solution will not delete words A11 but instead of words that begin with A11:

    with raw_data as)

    Select the 1 id, str "A11P75 P76 R01 U01 A11MIDDLE U40 U42 V53 VL VR A11FAKE' of the double

    )

    SELECT id,

    Str,

    -case when instr (replace (substr (str, instr (str,' ', - 1, 3)), "A11", "#"), "#") > 1

    then replace (str, 'A11', ")

    of another str

    End expected

    of raw_data

    /

    ID STR                                                          EXPECTED
    ---------- ------------------------------------------------------------ -----------------------------------------------------
    1 A11P75 P76 R01, U01 A11MIDDLE U40-U42 V53 A11FAKE A11P75 P76 R01 U01MIDDLE U40-U42 V53 VRFAKE VL VL RV

    SQL >

    In any case, something like:

    with raw_data as)

    Select the 1 id, str "A11P75 P76 R01 U01 U12 U40 U42 V53 VL VR A11' Union double all the

    Select 2, str "A11P75 P76 R01 U01 U12 U40 U42 V53 VL VR' Union double all the

    Select 3, str "A11P75 P76 R01 U01 U12 U40 U42 V53 VL A11 VR' Union double all the

    Select option 4, str "A11P75 P76 R01 U01 U12 U40 U42 V53 A11 VL VR' Union double all the

    Select 5, str "P75 P76 R01 A11 U01 U12 U40 A11 U42 V53 VL VR" of double

    )

    SELECT id,

    Str,

    case

    Where regexp_like (str,'(^ |) (\s+))A11(\s+\w+){2}$) ')

    then regexp_replace (str '(^ |) (\s+))A11((\s+\w+){2}$)','\3) ')

    Where regexp_like (str,'(^ |) (\s+))\w+\s+A11\s+\w+$) ')

    then regexp_replace (str,'((^ |))) (\s+))\w+\s+)A11\s+(\w+)$','\1\4) ')

    Where regexp_like (str,'(^ |) (\s+))\w+\s+\w+\s+a11$) ')

    then regexp_replace (str,'((^ |))) (\s+))\w+\s+\w+)\s+a11$','\1) ')

    of another str

    End expected

    of raw_data

    /

    ID EXPECTED STR
    ---------- --------------------------------------------------- ---------------------------------------------------
    1 A11P75 P76 R01, U01 U12 U40-U42 V53 VR A11 A11P75 P76 R01, U01 U12 U40-U42 V53 RV VL VL
    A11P75 2 P76 R01, U01 U12 U40-U42 V53 A11P75 P76 R01, U01 U12 U40-U42 V53 RV VL VL RV
    3 A11P75 P76 R01, U01 U12 U40-U42 V53 VL A11 A11P75 P76 R01, U01 U12 U40-U42 V53 VL VR VR
    A11P75 4 P76 R01, U01 U12 U40-U42 V53 A11 VL A11P75 P76 R01, U01 U12 U40-U42 V53 VL VR VR
    5 P75 P76 R01 A11 U01 U12 U40 A11 U42 V53 RV VL R01 A11 U01 U12 U40-U42 V53 VL VR A11 P76 P75

    SQL >

    SY.

  • Manipulating strings using regular expressions

    Hello guys,.

    I stuck in a situation in which I want to extract specific data from a column of the table.

    Here are the values for a particular column in which I want to ignore the values as well as support in the support and who are as .pdf, .doc.

    TRIS (dibenzylideneacetone) dipalladium (0) 451CDHA.pdf

    AM57001A (ASRM549CDH). DOC

    Identity sulfate AM23021A (project)

    PG-1183. E.2 (0.25 mg CTF)

    AS149656A (DEV APPL AERO WHT PROVENTIL HFA)

    Report on the stability (ISR) annex.2 semi-solid form (internal information)

    TSE(batch#USLF000332)-242CDH, Lancaster synthesis.pdf

    Additive TR3018520A 1 (REF 3018520)

    AM10311A Particle size airjet by sieving (constant sieving) (project)

    ASE00099B additive (REF E000099) mesh 90

    Palladium AM37101_312-99 (Z11c) by DCP.doc

    PS21001A_1H - NMR.doc (PN 332-00)

    AM68311A (Q - a CP 33021.02) attachment

    Attachment AM68202-1 has (BioReliance No. 02.102006)

    I want below output to above the values for the column

    Trisdipalladium451CDHA

    AM57001A

    Identity AM23021A sulfate

    PG-1183. E.2

    ...

    ..

    .

    Thanks in advance

    Like this?

    SQL> with t  2  as  3  (  4  select 'Tris(dibenzylideneacetone)dipalladium (0) 451CDHA.pdf' str from dual  5  union all  6  select 'AM57001A(ASRM549CDH).DOC' str from dual  7  union all  8  select 'AM23021A Identity of sulfate (draft)' str from dual  9  union all 10  select 'PG-1183.E.2 (0.25 mg FCT)' str from dual 11  union all 12  select 'AS149656A (DEV AERO APPL HFA WHT PROVENTIL)' str from dual 13  union all 14  select 'Stability report (RSR) Annex2 semi-solid form (internal information)' str from dual 15  union all 16  select 'TSE(Batch#USLF000332)-242CDH, Lancaster synthesis.pdf' str from dual 17  union all 18  select 'TR3018520A Addendum 1 (PN 3018520)' str from dual 19  union all 20  select 'AM10311A Particle size air-jet sieving (constant sieving) (draft)' str from dual 21  union all 22  select 'ASE00099B Addendum (PN E000099) 90 mesh' str from dual 23  union all 24  select 'AM37101_312-99 (Z11c) Palladium by DCP.doc' str from dual 25  union all 26  select 'PS21001A_1H-NMR.doc (PN 332-00)' str from dual 27  union all 28  select 'AM68311A (Q-One CP 33021.02) Attachment' str from dual 29  union all 30  select 'AM68202-1A (BioReliance no. 02.102006) Attachment' str from dual 31  ) 32  select str 33      , regexp_replace(str, '(\([^)]+\))|(\..{3})') str_new 34    from t;
    
    STR                                                                    STR_NEW---------------------------------------------------------------------- --------------------------------------Tris(dibenzylideneacetone)dipalladium (0) 451CDHA.pdf                  Trisdipalladium  451CDHAAM57001A(ASRM549CDH).DOC                                              AM57001AAM23021A Identity of sulfate (draft)                                  AM23021A Identity of sulfatePG-1183.E.2 (0.25 mg FCT)                                              PG-1183AS149656A (DEV AERO APPL HFA WHT PROVENTIL)                            AS149656AStability report (RSR) Annex2 semi-solid form (internal information)  Stability report  Annex2 semi-solid formTSE(Batch#USLF000332)-242CDH, Lancaster synthesis.pdf                  TSE-242CDH, Lancaster synthesisTR3018520A Addendum 1 (PN 3018520)                                    TR3018520A Addendum 1AM10311A Particle size air-jet sieving (constant sieving) (draft)      AM10311A Particle size air-jet sievingASE00099B Addendum (PN E000099) 90 mesh                                ASE00099B Addendum  90 meshAM37101_312-99 (Z11c) Palladium by DCP.doc                            AM37101_312-99  Palladium by DCPPS21001A_1H-NMR.doc (PN 332-00)                                        PS21001A_1H-NMRAM68311A (Q-One CP 33021.02) Attachment                                AM68311A  AttachmentAM68202-1A (BioReliance no. 02.102006) Attachment                      AM68202-1A  Attachment
    
    14 rows selected.
    
  • Chips with 3 delimiter characters using regular expressions

    Hello world

    I have a function that is able to mark the input in a collection string using regular expressions.

    In case the input string is a character such as the comma or semicolon delimiter,

    We can just get the result we want like the example below.

    SQL> select * from v$version;
    
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    

    SQL> with tab1 as (
      2      select 'abc,dfg,h,,1234' as col1 from dual
      3  )
      4  select regexp_substr(col1, '([^,]*)(,|$)', 1, level, 'i', 1) as result
      5  from tab1
      6  connect by level <= regexp_count(col1, ',')+1;
    
    
    RESULT
    ---------------
    abc
    dfg
    h
    
    1234
    

    But in the case where the channel of entry has 2 types of delimiter and each delimiter consists of 3 characters as below

    I wonder if it is possible to get the result as below.

    The input string: 01| ^ | ABCD| ^ | 111| * | 02| ^ | efgh| ^ | 222

    Separators: | * | is divided into lines, | ^ | is divided into columns

    Expected result:

    col1 col2 col3

    Row1 - > 01 abcd 111

    row2-> efgh 02 222

    Simply put, take a next

    The input string: 01| ^ | ABCD |^| 111 |*| 02 |^| efgh |^| 222

    Separator: | * |

    Result:

    01. ^ | ABCD | ^ | 111

    02. ^ | efgh | ^ | 222

    How can I achieve this using regular expressions?

    Kind regards

    Euntaek

    You need to know the number of the column from the outset:

    with tab1 as)

    Select ' 01 | ^ | ABCD | ^ | 111. * | 02. ^ | efgh | ^ | 222' as double col1

    )

    Select rownum,

    regexp_substr (regexp_substr (col1 '(.*?) ((\|\*\|)| $) ', 1, level, null, 1),'(.*?) ((\|\^\|)| $) ', 1, 1, null, 1) col1,.

    regexp_substr (regexp_substr (col1 '(.*?) ((\|\*\|)| $) ', 1, level, null, 1),'(.*?) ((\|\^\|)| $) ', 1, 2, null, 1) col2.

    regexp_substr (regexp_substr (col1 '(.*?) ((\|\*\|)| $) ', 1, level, null, 1),'(.*?) ((\|\^\|)| $) ', 1, 3, null, 1) col3

    of tab1

    connect by level<= regexp_count(col1,'\|\*\|')="" +="">

    /

    ROWNUM COL1 COL2 COL3

    ---------- ----- ----- -----

    1 01 abcd 111

    2 efgh 02 222

    SQL >

    SY.

  • To delete the characters only at the beginning of a string using regexp_replace

    I want to be able to delete the characters in a string only until the first numeric value.  If it takes place after the digital, I want to keep them.

    "for example"AB1234' becomes '1234', 'AB1234C' becomes ' 1234 C.

    It might be also spaces and other types of characters at the beginning.  I tried this:

    Select

    regexp_replace ('ABC1234', ' [^ [: digit:]]').

    regexp_replace ('AB 1234',' [^ [: digit:]]').

    regexp_replace ('AB 01234',' [^ [: digit:]]').

    regexp_replace ('AB1234C', ' [^ [: digit:]]').

    regexp_replace ('^ 1234', ' [^ [: digit:]]').

    regexp_replace ('* #1234Z ',' [^ [: digit:]]')

    OF THE DOUBLE

    For all except "AB 01234' returned '1234' so it retains the digital.    For "AB 01234' it returns correctly '01234'

    The bad are those with a character after digital, for example "AB1234C".

    I know it I'm missing something here, can someone please help with this?

    Thank you

    SQL> with t
      2  as
      3  (
      4  select 'ABC1234' str from dual
      5  union all
      6  select 'AB 1234' str from dual
      7  union all
      8  select 'AB 01234' str from dual
      9  union all
     10  select 'AB1234C' str from dual
     11  union all
     12  select '^1234' str from dual
     13  union all
     14  select '*#1234Z' str from dual
     15  )
     16  select str
     17       , regexp_replace(str, '^[^[:digit:]]+') str_new
     18    from t;
    
    STR      STR_NEW
    -------- --------
    ABC1234  1234
    AB 1234  1234
    AB 01234 01234
    AB1234C  1234C
    ^1234    1234
    *#1234Z  1234Z
    
    6 rows selected.
    
  • Find the words (wild cards) using regular expressions

    I'm testing to see if the words are present for revision 1 of a drawing of the cartridge.

    The script search the digit 1 followed by a date, a title, and 4 sets of initials.

    The number 1 is static, (date, title and original are the cards that they are different for each design).

    I use regular expressions to match the words.

    The regular expression highlighted in blue is the number 1 and the date.

    Him remains highlighted in orange does not match the title and initials.

    If anyone can help with the regular expression that is most appreciated.

    Once I got that work will add the form fields for the initials, noting only the console at this point for the tests.

    numWords = this.getPageNumWords (0);

    number of words on the page

    loop through the words on the page

    for (var j = 0; j < numWords-1; j ++)

    {/ / get the pair of words to test}

    ckWords = this.getPageNthWord (0, j) + ' ' + this.getPageNthWord (0, j + 1); test words

    Check if 1 26.05.16 THE STRENGTHENING REVISED MM SB AE GM word string is present

    If (ckWords.match(/ ^ 1\s [0-9] {1,2}.)) [0-9] {1,2}. [0-9] {2} \s\w+(\s+\w+){1,7}/))

    {

    Console.println (ckWords);

    }

    }

    You can use something like this:

    ckWords = this.getPageNthWord (0, j) + ' ' + this.getPageNthWord (j, 0, + 1) + ' ' + this.getPageNthWord (0, + 2 j) + ' ' + this.getPageNthWord (0, j + 3) + ' ' + this.getPageNthWord (0, j + 4) + ' ' + this.getPageNthWord (0, j + 5) + ' ' + this.getPageNthWord (0, j + 6);

    If (! ckWords.match (/ ^ 1\s\d {1,2} \.\d {1,2} \.\d {2} \s\w+ (?:-s + \w +) {1.8} \s([A-Z]{2})\s([A-Z]{2})-s ([A - Z] {2}) \s([A-Z]{2})$ /)) ckWords + ckWords + "" + this.getPageNthWord (0, j + 7);

    If (! ckWords.match (/ ^ 1\s\d {1,2} \.\d {1,2} \.\d {2} \s\w+ (?:-s + \w +) {1.8} \s([A-Z]{2})\s([A-Z]{2})-s ([A - Z] {2}) \s([A-Z]{2})$ /)) ckWords + ckWords + "" + this.getPageNthWord (0, j + 8);

    If (ckWords.match (/ ^ 1\s\d {1,2} \.\d {1,2} {2} \s\w+ \.\d (?:-s + \w +) 1.8 ([A - Z] {2}) \s([A-Z]{2})\s([A-Z]{2})\s {} \s([A-Z]{2})$ /))

    {

    ...

  • String format using regular expressions

    Input string output format...
    
    SELECT q'<select ab_c "ABC", efg "EFG" from dual>' str FROM DUAL
    
    Output:
    
    STR                                  
    -------------------------------------
    select ab_c "ABC", efg "EFG" from dual
    
    
    Required output format using regular expression...
    
    
    STR                                  
    -------------------------------------
    select 'ab_c' "ABC", 'efg' "EFG" from dual

    Regular expressions have many limitations as tools of analysis, and you specify the rules you want. This expression puts quotation marks around a non-empty string before a quoted string:

    SELECT regexp_replace(q'