the simple regular expression problem

Hello

I need assistance with regular expressions. I have a situation when I need to get data from one table to the other and I think that my problem can be solved using REG EXP, but I don't know how to use them properly.


I need to separate fileld varchar2 which is basically number/number in 2 separate number fields
 


CREATE TABLE tst (CODE VARCHAR2(10)); 

INSERT INTO tst VALUES('10/15'); 
INSERT INTO tst VALUES('13/12'); 
INSERT INTO tst VALUES('30'); 
INSERT INTO tst VALUES('15'); 

CREATE TABLE tst2 (po NUMBER, co NUMBER); 
I need to get the code in the co and po columns. I think the result should look something like this, but:
 

INSERT INTO tst2 
SELECT regexp_substr(CODE 'something here to get the number before /') AS po, 
       regexpr_substr(CODE 'something here to get number after') AS co 
FROM tst;   
Any help appreciated

Agree with the above,

However, if you really want to know how to do with regular expressions you can do it like this...

SQL> select regexp_substr('10/15','[^/]+',1,1) from dual;

RE
--
10

SQL> select regexp_substr('10/15','[^/]+',1,2) from dual;

RE
--
15

Tags: Database

Similar Questions

  • The regular expression problem

    Dear friends,

    In my script I have some sections that test the contents of an edit field before it is processed further.

    Perfectly things like the following:

    var re_Def = /#[A-Za-z][A-Za-z0-9_]+/;          // valid variable name ?
    items = ["#correct", "notcorrect", "#This_is4", "#thisIs", "@something", "#ALLOK", "", ];
    // search    0            -1          -1!!        -1!!          -1        -1!!     -1      <--- incorrect method
    // test    true         false         true        true        false       true    false    <--- correct method
    for (var j = 0; j < items.length; j++) {
      var item = items[j];
      alert ("'" + item + "' ==> " +  item.search(re_Def) + "\n" + re_Def.test(item));
    }
    var re_Def = /(\[ROW +\d+\]|\[COL +\d+\]|\[CELL +\d+, +\d+\]|Left *\(\d*\)|Right *\(\d*\)|Above *\(\d*\)|Below *\(\d*\))/;
    items = ["[ROW 17]", "[Row n]", "[ROW n]", "[CELL 3, 9]", "[CELL 3 9]", "Abbove()", "Right(3)"];
    // result  true        false      false         true         false        false         true    
    for (var j = 0; j < items.length; j++) {
      alert ("'" + items[j] + "' ==> " +  re_Def.test(items[j]));
    }
    

    But what follows always returns false, independly of the content of the string element:

    var re_Def = /{[EFJ]\d*}|{I}/;    // valid format def?
    var item = "{E27}";
    var result = re_Def.test(item);
    alert (result);                   // false !!
    

    RegEx buddy told me, that
    -l' REGULAR expression is correct
    -the result must be true, not false

    -The verbose definition of the RegEx is:
    Match is the following regular expression (attempting the next alternative only if this one fails) "{\d* [EYF]}."
    Match the character "{" literally "{}".
    Match a single character present in the list "J" "[EYF]."
    Match a single digit 0. 9 paper"\d*»
    Between zero and unlimited times, as many times as possible, giving as needed (greedy) «*»
    Match the character "}" literally "}".
    Or match number 2 below (the entire match attempt fails if it cannot match) regular expression "{i}".
    Match the characters "{i}" literally "{i}".

    Typo unrecognized? Test the faulty method?

    Results are fake, as soon as I use the list of characters []] - but look at the first block of code: there are also lists of character they are treated properly.

    The braces in the regular expression must be escaped to be taken literally:

    var re_Def = /\{[EFJ]\d*\}/;
    

    Kind regards

    JoH

  • Need help with a simple regular expression replacement

    Hello everyone,

    He comes to the table that I have to work with.
    CREATE TABLE "TBL_ACCOMMODATION" ("ACCOMMODATION_ID" NUMBER, "HOTEL_NAME" VARCHAR2(100), "ADDRESS" VARCHAR2(200), "LOCATION" VARCHAR2(100), "PHONE" VARCHAR2(50), "EMAIL_ADDRESS" VARCHAR2(60), "CONTACT_PERSON" VARCHAR2(60), "STATUS" CHAR(1), "CREATED_BY" VARCHAR2(10), "CREATED_DATE" DATE, "MODIFIED_BY" VARCHAR2(10), "MODIFIED_DATE" DATE, "MOBILE" VARCHAR2(50))
    REM INSERTING into TBL_ACCOMMODATION
    Insert into TBL_ACCOMMODATION (ACCOMMODATION_ID,HOTEL_NAME,ADDRESS,LOCATION,PHONE,EMAIL_ADDRESS,CONTACT_PERSON,STATUS,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE,MOBILE) values (147,'Testt','Auckalnd','Henderson','565756776','[email protected]','Jasmine','A',null,null,'JEEJJ',to_date('23/10/12','DD/MM/RR'),null);
    Insert into TBL_ACCOMMODATION (ACCOMMODATION_ID,HOTEL_NAME,ADDRESS,LOCATION,PHONE,EMAIL_ADDRESS,CONTACT_PERSON,STATUS,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE,MOBILE) values (129,'Kirby Hotel','25A Aitken Street
    Wellington','Wellington','04 918 8513','[email protected]','Deahdoow Maharg','A',null,null,'LEAN',to_date('14/02/13','DD/MM/RR'),'027 356 4333');
    Insert into TBL_ACCOMMODATION (ACCOMMODATION_ID,HOTEL_NAME,ADDRESS,LOCATION,PHONE,EMAIL_ADDRESS,CONTACT_PERSON,STATUS,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE,MOBILE) values (167,'Avenue ee','10 Wellington Street
    Wellington','Wellington','4444444','[email protected]','James','A',null,null,'LEAN',to_date('21/02/13','DD/MM/RR'),null);
    Insert into TBL_ACCOMMODATION (ACCOMMODATION_ID,HOTEL_NAME,ADDRESS,LOCATION,PHONE,EMAIL_ADDRESS,CONTACT_PERSON,STATUS,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE,MOBILE) values (185,'Quadrant Hotel','10 Waterloo Quadrant,
     Auckland','Auckland','9555555','[email protected]','Quentin QQ','A',null,null,'LEAN',to_date('04/03/13','DD/MM/RR'),null);
    My select statement is
    SELECT acc.hotel_name || '(' || replace(replace(acc.address,chr(13),', '),',,',',') || ')'
    FROM TBL_ACCOMMODATION acc
      inner join ijs_seminar s ON acc.accommodation_id = s.accommodation_id 
    where s.seminar_id = :P27_SEMINAR_ID
    I have to use the function replace twice. One is to replace the Chr (13) a comma is second band a comma where there are two commas.

    I don't know much about regular expressions.
    If someone can show me a better way to handle this using the regular expression rather than a heavy means above.

    Thanks in advance
    Ann

    Hi, Ann.

    Ann586341 wrote:
    Hello everyone,

    He comes to the table that I have to work with.

    CREATE TABLE "TBL_ACCOMMODATION" ("ACCOMMODATION_ID" NUMBER, "HOTEL_NAME" VARCHAR2(100), "ADDRESS" VARCHAR2(200), "LOCATION" VARCHAR2(100), "PHONE" VARCHAR2(50), "EMAIL_ADDRESS" VARCHAR2(60), "CONTACT_PERSON" VARCHAR2(60), "STATUS" CHAR(1), "CREATED_BY" VARCHAR2(10), "CREATED_DATE" DATE, "MODIFIED_BY" VARCHAR2(10), "MODIFIED_DATE" DATE, "MOBILE" VARCHAR2(50))
    REM INSERTING into TBL_ACCOMMODATION
    Insert into TBL_ACCOMMODATION (ACCOMMODATION_ID,HOTEL_NAME,ADDRESS,LOCATION,PHONE,EMAIL_ADDRESS,CONTACT_PERSON,STATUS,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE,MOBILE) values (147,'Testt','Auckalnd','Henderson','565756776','[email protected]','Jasmine','A',null,null,'JEEJJ',to_date('23/10/12','DD/MM/RR'),null);
    ...
    

    Thanks for posting the sample data. You post the results, but the validation of the existing query which I suppose, produced good results. I can't run this query, because it requires the ijs_seminar table and a connection variable that also has no post, but I can just comment on the join and the WHERE clause.

    Is this really the best set of sample data for this question? This problem involves Chr (13) and repeated commas, but I don't see any s CHR (13) or repeated commas in the sample data. In addition, it seems that there are a lot of columns that play no role in this issue and just to make things difficult to read.

    My select statement is

    SELECT acc.hotel_name || '(' || replace(replace(acc.address,chr(13),', '),',,',',') || ')'
    FROM TBL_ACCOMMODATION acc
    inner join ijs_seminar s ON acc.accommodation_id = s.accommodation_id
    where s.seminar_id = :P27_SEMINAR_ID
    

    I have to use the function replace twice. We need to replace the Chr (13) by a comma,.

    As posted, inside REPLACE replaces Chr (13) with a comma and a space which could be important if you then pick up consecutive commas.

    second is the band a comma where there are two commas.

    I don't know much about regular expressions.
    If someone can show me a better way to handle this using the regular expression rather than a heavy means above.

    Assuming you want to replace Chr (13) with just a comma, then an equivalent would be:

    SELECT    acc.hotel_name || '('
                      || REGEXP_REPLACE ( acc.address
                                          , '[,' || CHR (13) || ']{1,2}'
                                , ','
                                )
                    || ')'            AS h
    FROM        tbl_accommodation acc
    INNER JOIN  ijs_seminar       s   ON   acc.accommodation_id = s.accommodation_id
    WHERE s.seminar_id = :P27_SEMINAR_ID
    ;
    

    In the argument to REGEXP_REPLACE 2nd

    [xy]{1,2}
    

    medium 1 to 2 characters of set of x and y. This could be
    x or
    there or it could be 2 characters
    XY or the other way
    YX or it could be the same characters 2
    XX or
    YY

    REGEXP_REPLACE is slower that REPLACE. Even if your original expression is longer, it may be more effective. (Performance may be not a problem in this case.)

  • Regular expressions - problem

    Hi @ all,

    I need a regular expression more difficult, I don't know Don t.

    I have a big file with many pages .htm (800-1000) and I have to do the following:

    http://www.domain.de/ AB % 32-xyz? myshop = 123

    I have to delete the "ab % 32-xyz", the problem is, that it is, it could be each symbol, the letter or digit.

    Then the area between " " http://www.domain.de/ ' 'and'? myshop = 123 "(these 2 areas are identical in all documents each time) should be removed.

    Anyone could tell me how to do this with regular expressions in dreamweaver?

    Thank you

    Felix

    P.S.: Sorry, my English is not so good, I m from the Germany

    You want to replace the random text with anything?

    If this is not the case, this is how you do in DW:

    1. Make a backup of the folder that you want to change, just in case something goes wrong
    2. Edition > search and replace
    3. In the find and Replace dialog box, select the folder in the menu drop-down "search in" and select the folder that you want to use.
    4. Select the Source Code from the drop-down search menu.
    5. Place the following code in the search text box:
      (http://www \.domain\.de/) [^?] +(\? MYshop = 123)
    6. Place the following code in the text box replace:
      $1$ 2
    7. In Options, select the checkbox "use regular expression.
    8. Click on replace all. Dreamweaver warns you that the operation cannot be undone in pages that are not currently open. As long as you have made a backup, click OK to run the operation.
  • Simple regular expression

    Hello

    I need a simple check to validate if a string contains only letters and numbers.

    The regular expression to test this should be

    [A Za-z0-9]

    or, to check out the entire string to start ebd

    ^ [A Za-z0-9] $


    Now it is refined and the return match to search a string for the given expressions.

    The first expression matches any character, anywhere in the string.

    The second expression is not at all (although using regex validator test online).

    How to do this correctly for my goal, namely, to validate if a string contains only letters and numbers.

    Thank you!

    I would like to know what regex testers online you used as the second regex actually worked for your needs.  So I know to avoid them because they don't work well.

    Your two regexes only to a single character.  Then a second will match only one character alphanumeric strings.  Want to make a game of several character, with a ' + '.

    --

    Adam

  • meaning of the given regular expression

    Hi all
    I want to know how the regular expression in the following query.

    SELECT UNIQUE REGEXP_REPLACE (catalog_url, ' http:// (\ [^ /-] +). * ', '\1')
    OF oe.product_information;

    Here I put spaces for ease of understanding.
    Soni

    Published by: sonidba on February 5, 2010 12:28

    Published by: sonidba on February 5, 2010 12:30

    sonidba wrote:
    Thanks for your reply. I am knowing the answer only. But not how. What does '\1' referred to here in the request. Someone at - it the answer?

    Published by: sonidba on February 5, 2010 13:04

    \1 is a backreference.

    In the REGEXP_REPLACE function (catalog_url, ' http:// ([^ /] +). * ', '\1') there is a section of the chain of research in parentheses. \1 refers to the found value that corresponds to that subexpression. If you had several subexpressions in parentheses then you may have several backreferences.

  • The match regular expression or pattern

    I'm in big trouble to the extraction of results of a string of serial port.
    I get a report through connectio series of some devices. It looks like this:

                                        Plane 1 Angle 1 Plane 2 Angle 2 In
    
         RotorID      rpm            [g·mm]    [°]    [g·mm]    [°]  Tol
                              1964.7     0.145999  201.6 0.151779  346.5 Y
                              2014.5     0.156608  197.6 0.139722  340.9 Y
             ealon ok     2012.1     0.143454  199.8 0.150243  344.6 Y
             ealon nok    2023.3    0.430547  217.7 0.833347  313.3 Y
             DN-3259824_001  2135.9 0.305822  246.2 0.296502  305.2 Y
             DN-3259824_002  2051.4 0.324227  241.1 0.327651  299.0 Y
             DN-3259824_020  2045.9 0.139268  150.2 0.281890   21.6 Y
    

    I can't separate the data with spaces, because sometimes there is no "RotorID" so that all data is moved to the left.
    There are still 7 columns. RotorID is sometimes empty sometimes that he composed characters and numbers. I never know its length. Other data are still present and separated with space.

    Can you help me please.

    If you want to use a regular exprission.

  • Regular expression, problem when literals have content "I_".

    Hello

    I guess it seems to be a bug/defect of Oracle. If I do this wrong, please let me know.
    I need to remove the "_VERSION' coming to the latest in a string column. For example, if the string is WINDOWS_XP_VERSION, then the output should be WINDOWS_XP.

    But if you run the query below

    SELECT
    REGEXP_SUBSTR (['AA_TEST_3_XI_VERSION ',' \w+[^_VERSION]') t1.
    REGEXP_SUBSTR (['AA_TEST_3_Xi_VERSION ',' \w+[^_VERSION]') t2.
    REGEXP_SUBSTR (['AA_TEST_3_XIA_VERSION ',' \w+[^_VERSION]') t3
    FROM DUAL;


    T1 T2 T3
    AA_TEST_3_X AA_TEST_3_Xi AA_TEST_3_XIA

    1 selected lines

    It seems that the problem exists only when I use "I_" and works well with "i_". I checked with a few other characters and everything worked fine.
    Any ideas? I use 11g.

    Thank you
    Sharmin

    any string that does not "_VERSION", it would return NULL

    You would need a small correction:

    SQL> with t as (
     select 'AA_TEST_3_XV_VERSION' str from dual union all
     select 'AA_TEST_3_XE_VERSION' from dual union all
     select 'AA_TEST_3_XIR_VERSION' from dual union all
     select 'AA_TEST_3_XIR' from dual
    )
    
    select regexp_substr (str, '(\w+?)(_VERSION)?$',1,1,null,1) str
      from t
    /
    STR
    -------------------------------
    AA_TEST_3_XV
    AA_TEST_3_XE
    AA_TEST_3_XIR
    AA_TEST_3_XIR                  
    
    4 rows selected.
    
  • Analyze the Mac address with the regular expression matching

    Hello world

    I have a problem with the function of regular expression matching,

    I try to analyse the response both a query arp - a 192.168.0.15 to retrieve the MAC address of the remote IP address, I used the following regular expression: ^ ([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})$

    I wonder why should I do a subset of the first string to extract only the part of the MAC address. The regular Expression function is not able to recognize the regular expression directly in the middle of a string?

    I only works when I extracted the subset of tring right as in the picture below.

    Thanks for your replies.

    Get rid of the "^" at the beginning of your regular expression. You are ordering him to find the model at the beginning of the string.

  • regexp_substr: a regular expression for the separate comma operator of witn of string literals IN

    The following regular expression separates simple values separated by commas (SELECT regexp_substr (: pCsv,'[^,] +', 1, level) FROM DUAL CONNECT BY regexp_substr (: pCsv, ' [^,] +', 1, level) IS NOT NULL); Exampple: 300100033146068, 300100033146071, 300100033146079 returns 300100033146068 300100033146071 300100033146079

    This works very well if we use the regex with SQL IN operator select * from mytable where t.mycolumn IN (SELECT regexp_substr (: pCsv,'[^,] +', 1, level) FROM DUAL CONNECT BY regexp_substr (: pCsv, ' [^,] +', 1, level) IS NOT NULL);

    But this query does not work if the comma-separated value is a single literal string 'one', 'two', 'three '.

    Thanks for your reply. my request was mainly on regexp_substr.  Need to request was simple: any table with a column of varchar type can be used. Next time I'll give you an example.

    All ways working answer for my question is is SELECT regexp_substr (: pCsv,'[^, "] +', 1, level) FROM DUAL CONNECT BY regexp_substr (: pCsv, ' [^,"] +', 1, level) IS NOT NULL

  • Looking for the character "$" in a regular expression

    I try to use the vi "Regular Expression to Match", but what I'm trying to find is a dollar sign followed by a space.

    Using the slash codes allows me to specify a whitespace character (\s) but I can't find how to specify the $.

    I tried \x24 and \36 try hex and decimal ASCII representations, but no luck, I tried to put the $ hooks - but which doesn't work either.

    Everything I try, the $ is interpreted as a command rather than the search term.

    I used to use model game (legacy code) and the search term "$\s*$ ' worked - now need to use regex that I need to feed in some other matches this regex only can do - except for the dollar (if only I worked in the good old UK £!)

    Any ideas out there?

    Thank you

    I think that we must work...

    \\$\s[\n\r]

    seems to do the trick

  • Regular expression help please. (extraction of a subset of the string between two markers)

    I haven't used regular expressions before, and I can't find a regular expression to extract a subset of the string between two markers.

    The chain;

    Stuff of header I want
    Stuff of header I want
    Stuff of header I want

    Stuff of header I want
    Stuff of header I want
    Stuff of header I want

    6 ERRORS
                         
    Info I want to line 1
    Info I want line 2
    Info I want line 3
    Info I want to line 4
    Info I want to line 5
    Info I want line 6
    END_ERRORS

    From the string above (it is read from a text file), I try to extract the subset of string between ERRORS 6 and END_ERRORS. The number of errors (6 in this case) can be any number from 1 to 32, and the number of lines I want to extract will correspond with this number. I can provide this number of a caller VI if necessary.

    My current solution, which works, but is not very elegant;

    (1) using Match Regular Expression for the return of the string after you have synchronized the 6 ERRORS

    (2) uses the Regular Expression matches to return all characters before game END_ERRORS of the string returned by (1)

    Is there a way this can be accomplished using 1 Regular Expression Match? If so someone could suggest how, as well as an explanation of the work of the given regular expression.

    Thank you very much

    Alan

    I used a character class to catch any word or whitespace characters.  This put inside parentheses a substring matching the criteria that you can get by developing the node for regular expression matching.  The \d matches the numbers and the two * s repetition of the previous term.  So, \d* will find the '6', as well as "123456".

  • Form validation helps with the regular Expression [a-zA-Z]

    I'm trying to use the regular expression [a-zA-Z] to allow only upper or lowercase WITHOUT SPACES. With the help of [a-zA-Z] allows space and numbers.

    Could someone give me a point in the right direction?

    Thank you!

    RGNelson wrote:

    I'm trying to use the regular expression [a-zA-Z] to allow only upper or lowercase WITHOUT SPACES. With the help of [a-zA-Z] allows space and numbers.

    Could someone give me a point in the right direction?

    Please try with the following regular expression, which should work for text entry fields 'a line' well standard.

    ^ [A-Za-z] + $

    See you soon,.

    Günter

  • Regular expressions in the APEX

    I am using the following regular expression ^ [\w\s]+?$, but it does not work in APEX.] I want to validate a field for not accepting anything but the line of underscores, spaces and alphabetic characters.

    Try to use POSIX character classes:

    ^[[:alpha:][:space:]_]+?$
    

    Note that you must always provide at least the following information when you ask a question:

    -APEX version
    -Edition and version DB
    -Web server architecture (EPG, SST or APEX listener)
    -The browsers used
    -Theme used
    -Models

  • The regular Expression disorder

    Hello everyone, happy holidays.

    I create a component in an application that is similar to the function of Facebook's "News Feed". This feature lists the rows of a database that can contain 'special' text to be converted to HTML. Note: I'm store "special text" in the database instead of the HTML real to save space in the database where the object name is very long.

    Here's what I'm trying to do:

    In the database a record might look like this:
    12/25/06 [user: 253] John Smith [a] connected.

    When I display the table I want to convert to the following:
    12/25/06 < a href = "user_info.cfm? userId = 253" > logged in on John Smith < /a >.

    I was able to create the following regular expression, which does a good job of converting the text to a link, but I am unable to get the uniqueID (253) of the string. Note: The Description is the name of the column is being processed.

    < CFSET = temp ReReplace (Description,'-[user:.------] "," < a href = "user_info.cfm? userID = 253" > ', 'ALL') >
    < CFSET = temp ReReplace (temp,'\ [/ a\]', '< /a >', 'ALL') >

    Is there a way I can convert the string into a regular expression? Also, how can I get the number value after the colon (:) and insert it in the replacement string?)

    In addition, to complicate things, the string can have multiple instances of "special text". For example:
    12/25/06 [user: 253] John Smith [a] changed account [user: 262] Captain Picard [a]

    Thanks for your help!

    The (. *) part of your regex can capture more than desired for the following user ID.

    Maybe this will do as you wish.

    -tom-

Maybe you are looking for

  • Unable to connect to google after installing windows 10 "secure connection failed".

    I installed windows 10 today. now, every time that I can't get to google/youtube to firefox, internet explorer and opera. I get this error: "Secure connection failed". The connection on www.google.com while the page is loading. The page you are tryin

  • Satellite Pro 2100 Wont initialize the

    Have used this laptop for many years without any problems, that is until today. the laptop will not start.DC in 15V Ok.Light green power on.Green on drums.HARD drive integrated offshore.When I pressed the Start button, thought I heard two short beeps

  • CAN communicate with Veristand

    Hello I use a CRIO9081 with a module CAN 9268. I made a good configuration with detection of MAX module, power module, adding CAN wear under a Veristand project and I have NI-XNET... Now I want to interact with a sensor using CDN per Veristand, but I

  • Re: Buzzing/buffering sound every few seconds when the streaming videos online.

    I'm having the same problem. I followed your steps with the sound and even the glitching. Any other suggestions? Everything is updated, I use windows 8.1 it seems to be a little better on the Netflix App, but from time to time it will happen. Cannot

  • Light of Perrier 6.1

    Light of Perrier 6.1, I installed but it does not work on vista premium window. Can run on Windows vista? If so, how?