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.

Tags: Database

Similar Questions

  • 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 
    
  • 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})$ /))

    {

    ...

  • A special character validation using regular expressions in ADF

    Hi guys,.

    I want to put the validation of a special as character (,.') ((en) &, -) using regular expressions.

    I asked the posting as [a-zA-Z0-9'(.),--/ &] but it does not work properly.

    Special characters should be like:

    Comma,

    Hyfan-

    Dot.

    Open and close braces (and).

    Ampercent &

    Apastrophy '

    Space ""

    Please help if anyone has idea.

    And I also tried to put under expression as...

    [a-zA-Z] + (\\s* [0-9] * [a-zA-Z] *-* & * \\(*\\) *, *'*. *) * [a-zA-Z0-9] + but we need the validation if we put special characters between the charater as "ab," chain "& (bc).

    his does not work if I put a special character at the beginning and the end of the string in the ADF

    Thanks Timo...

    its working fine...

  • ADF Email of Validation using regular expressions

    Hello

    Wanted to add search Email Validation VO.

    It works if I put
    <af:validateRegExp pattern="[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}" 
                                             messageDetailNoMatch="The value {1} is not a valid email address:"/>
    However, this requires identification of email to be entered in capital letters.

    I tried with below the option does not work.
                   <af:inputText value="#{bindings.xxEmail.inputValue}" label="Email"
                                          required="#{bindings.xxEmail.hints.mandatory}"
                                          columns="#{bindings.xxEmail.hints.displayWidth}"
                                          maximumLength="#{bindings.xxEmail.hints.precision}"
                                          shortDesc="#{bindings.xxEmail.hints.tooltip}" id="it5">
                                <f:validator binding="#{bindings.xxEmail.validator}"/>
                                <f:validateLength minimum="6"/>              
                                <af:validateRegExp pattern="[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}" 
                                             messageDetailNoMatch="The value {1} is not a valid email address:"/>
                            </af:inputText>
    I got over information of
    ADF Email of Validation using regular expressions
    The user enter email id without @.



    Please suggest this model to reach.


    Thank you
    JIT

    Published by: appsjit on January 25, 2013 19:08

    Hello.
    My English is not very good.

    I use below format and it works


    "^ [_A-Za-z0 - 9-] + (\.). [_A-Za-z0-9-]+)*@[A-Za-z0-9][A-Za-z0-9-]+ (-.)] ([A Za-z0-9] +) * (-.) [A-Za - z] {2,}) $»
    messageDetailNoMatch = "the value {1} is not a valid email address" / >

    Habib

    Published by: Habib Eslami on January 26, 2013 01:22

  • validate cfinput using regular expressions

    Hello

    can someone help me valditing a field of cfinput using regular expressions?

    First digit must be a number or a 'R '.

    Figure 2-15 can be anything without special characters. Figure 2-15 can also be empty.

    I try this, but it does not work (sorry I'm a beginner using regex).

    < cfinput type = "text" name = "field1" required = "yes" validate = 'regular_expression' pattern = "[0 - 9Rr] [0 - 9a - zA - Z]" * "maxlength ="15">"

    Thank you for advice!

    Claudia

    ^ [0 - 9Rr]([0-9a-zA-Z]{1,14})? $

  • Using regular expressions to solve sys_refcursor of a record

    Regarding my Question about sys_refcursor with record type of thread, I thought it can be solved differently. It is:

    I have a string like ' 8:1706, 1194, 1817 ~ 1:1217, 1613, 1215, 1250'

    I need to do a few things using regular expressions and get something like
    select * from <table> where
    c1 in (8,1)
    and c2 in (1706,1194,1817,1217,1613,1215,1250);
    Is it possible by using regular expressions in a single select statement?

    Hello

    Game 6' - 8 "wrote:
    Your understanding is quite correct. But unfortunately it doesn't Frank.

    SQL> SELECT COUNT (*)
    2    FROM (SELECT sp.*
    3            FROM spml sp, spml_assignment spag
    4           WHERE sp.spml_id = spag.spml_id
    5             AND spag.class_of_svc_id = 8
    6             AND spag.service_type_id IN (1706, 1194, 1817)
    7             AND spag.carrier_id = 4445
    8             AND NVL (spag.haulage_type_id, -1) = NVL (NULL, -1)
    9             AND spag.effdate = TO_DATE ('01/01/2000', 'mm/dd/yyyy')
    10             AND spag.unit_id = 5
    11             AND sales_org_id = 1
    12          UNION ALL
    13          SELECT sp.*
    14            FROM spml sp, spml_assignment spag
    15           WHERE sp.spml_id = spag.spml_id
    16             AND spag.class_of_svc_id = 1
    17             AND spag.service_type_id IN (1217, 1613, 1215, 1250)
    18             AND spag.carrier_id = 4445
    19             AND NVL (spag.haulage_type_id, -1) = NVL (NULL, -1)
    20             AND spag.effdate = TO_DATE ('01/01/2000', 'mm/dd/yyyy')
    21             AND spag.unit_id = 5
    22             AND sales_org_id = 1);
    
    COUNT(*)
    ----------
    88
    
    SQL> SELECT COUNT (*)
    2    FROM spml sp, spml_assignment spag
    3   WHERE sp.spml_id = spag.spml_id
    4     AND spag.carrier_id = 4445
    5     AND NVL (spag.haulage_type_id, -1) = NVL (NULL, -1)
    6     AND spag.effdate = TO_DATE ('01/01/2000', 'mm/dd/yyyy')
    7     AND spag.unit_id = 5
    8     AND sales_org_id = 1
    9     AND REGEXP_LIKE ('8:1706,1194,1817~1:1217,1613,1215,1250',
    10                      '(^|~)' || spag.class_of_svc_id || ':'
    11                     )
    12     AND REGEXP_LIKE ('8:1706,1194,1817~1:1217,1613,1215,1250',
    13                      '(:|,)' || spag.service_type_id || '(,|$)'
    14                     );
    
    COUNT(*)
    ----------
    140
    
    SQL> 
    

    Published by: release 6' - 8 "August 11, 2009 20:04

    Serving what you ordered!

    Originally, you said that you are looking for something that produces the same result as

    where   c1 in (8, 1)
    and      c2 in (1706, 1194, 1817, 1217, 1613, 1215, 1250)
    

    in other words, the c1s could be coupled with any of the c2s.
    Now, it seems that what you want is

    where     (     c1 = 8
         and     c2 IN (1706, 1194, 1817)
         )
    or     (     c1 = 1
         and     c2 IN (1217, 1613, 1215, 1250)
         )
    

    in other words, c1 = 8 and c2 = 1250 is not good; is not c1 = 1 and c2 = 1706.

    In this case, try

    WHERE     REGEXP_LIKE ( s
                  , '(^|~)' || c1
                         || ':([0-9]+,)*'
                         || c2
                         || '(,|~|$)'
                  )
    
  • How to extract the value of a tag XML using regular Expressions

    We get a response XML from a WEB SERVICE.

    I convert it to VARCHAR2.

    Now, I want to get the real answer that is inside the tag of the response.

    I tried this:

    DECLARE

    V_1 VARCHAR2 (30000): = ' < soap: Body > < ns:ProcessArgusFeedsResponse xmlns:ns = "urn: PegaRULES:SOAP:ArgusToPegaFeeds:Services" > ' |

    '< response > good < / answer >< / ns:ProcessArgusFeedsResponse > < / soap: Body > ';

    v_response VARCHAR2 (100);

    BEGIN

    DBMS_OUTPUT. PUT_LINE (V_1);

    v_response: = REGEXP_SUBSTR (v_1, ' / < >(.+?) < \/Response > answer /');

    dbms_output.put_line (v_response);

    END;

    It does not work.

    Any help would be greatly appreicated.

    Hello

    user12240205 wrote:

    We get a response XML from a WEB SERVICE.

    I convert it to VARCHAR2.

    Why?  XML has its own native ways of analysis; Why not use them?

    If you use regular expressions, then REGEXP_REPLACE, as shown above, is a good option in Oracle 10, but starting in Oracle 11.1, you can use REGEXP_SUBSTR like this:

    REGEXP_SUBSTR (v_1

    , '(.+?)'

    1

    1

    NULL

    1

    )

    The 6th argument is like a backreference; "He tells REGEXP_SUBSTR did not return to the entire organization, but only the part inside the 1st left '(' et correspondant à sa droite).

    The '?' to make it non-greedy is necessary only if v_1 can contain more than one response.

    Now, I want to get the real answer that is inside the tag of the response.

    I tried this:

    DECLARE

    V_1 VARCHAR2 (30000): = "" |

    'Good';

    v_response VARCHAR2 (100);

    BEGIN

    DBMS_OUTPUT. PUT_LINE (V_1);

    v_response: = REGEXP_SUBSTR (v_1, ' /(. +?)) <\ esponse="">/');

    dbms_output.put_line (v_response);

    END;

    It does not work.

    That's because it's looking for a slash ("/") before the '' tag and another after the ' tag.

    The backslash ("\") is not necessary here, but it is not nothing wrong.

  • 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'