using reg exp

Hello

I need to extract the first file name token (and not the directory path) of a string like this:

D:\MIRACLE\UPLOADS\1361\HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62
HG-ouA02 #xaldb #alertlog_contents #22022010111941.mirdf.loadfailed_240210095258_62
\HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62
/Hg-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62

the chips would be bed HG-ouA02 in all cases

Could you help me create a reg expression to get the token?

Best regards
Mette

Hello

Whenever you have a problem, it helps if you post your sample data in a form, people can use.
CREATE TABLE and INSERT statements are great. therefore:

CREATE TABLE     table_x
AS          select 'D:\MIRACLE\UPLOADS\1361\HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62'
               AS filename, 1 as x_id FROM dual
UNION ALL     SELECT 'HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62'
               AS filename, 2 as x_id FROM dual
UNION ALL     SELECT '\HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62'
               AS filename, 3 as x_id FROM dual
UNION ALL     SELECT '/HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62'
               AS filename, 4 as x_id FROM dual
;

It also helps if you explain how you get the results you want from these data.

Assuming that
(a) the name of file is divided, firstly, by ' / ' or ' \' characters, and
(b) each of these parts can be subdivided into tokens by '.' or the characters ' # ' and that
(c) we want the first part (b) of the last (part a):

SELECT     REGEXP_SUBSTR ( REGEXP_SUBSTR ( filename
                          , '[^/\]*$'
                          )
                , '[^.#]+'
                ) AS token_1
FROM     table_x;

Here the inner circle REGEXP_SUBSTR finds the last part delimited by / or \. You can add other delimiters by placing them in square parentheses, anywhere after ^.
The external REGEXP_SUBSTR works on the results of the Interior. He returned the first part bounded by. or #. Again, you can add other delimiters.

Tags: Database

Similar Questions

  • Reg exp query

    I want to separate al chain which are sperated by '-' using reg exp, could you please help me in this

    E WD-MS-HB-ON
    Thanks in advance

    Hello

    There seems to be some typos in response #1; Use the response form #2.

    For example, for the 3rd part the hyphen-delimited, use

    SELECT REGEXP_SUBSTR ('E-WD-MS-HB-ON"

    , ' [^-] +' - note + sign at the end

    1. this argument is always 1

    3. part wanted (1 or greater)

    ) AS part_3

    DOUBLE;

    If you publish no usable sample data, so people can not test their ideas, and makes makes much more likely wrong answers.

  • A doubt on REG EXP

    Hi friends,

    Please specify the doubt in Reg Exp.

    Table EMP a sequel EMP_NAMEs:

    ============
    Anand
    Bala_G
    Chitra
    David_C
    Elango
    Faye
    ============

    We have a set of characters as "abcdefghijklmnopqrstuvwxyz0123456789".

    Now we must find EMP_NAMES County, whose characters (any) are not in the list of characters in the list above. In this example, the result should be 2. for example, "Bala_D" and "David_C. The query should be like:

    Declare
    v_string varchar2 (50): = "abcdefghijklmnopqrstuvwxyz0123456789";
    v_count number (6);
    Begin
    Select count (*)
    in v_count
    WCP
    where regexp_like (emp_name, v_string);

    dbms_output.put_line (v_count);

    end;

    ========================

    Thanks in advance!

    Hello

    Welcome to the forum!

    To use REGEXP_LIKE, you could say:

    WHERE     REGEXP_LIKE ( emp_name
                  , '[^abcdefghijklmnopqrstuvwxyz0123456789]'
                  )
    

    However, it will be faster not not to use regular expressions:

    WHERE   LTRIM ( emp_name
               , 'abcdefghijklmnopqrstuvwxyz0123456789'
               )          IS NOT NULL
    

    Published by: Frank Kulash on 10 October 2012 16:18
    Removed the extra single quote, after DAMorgan, below.

  • How do you use the Exp fundtion on the windows calculator

    How do you use the Exp function in the windows for the following calculator

    Exponential of the negative power of 0.5

    e

    I don't have.
    I couldn't find an e = 2.71828183 key on the windows calculator.
    I used Google's built-in calculator function.

    The windows calculator, you will need to enter:
    2.71828183 [x ^ y] (-0.5) =.
    ||

  • using reg query

    Hello

    I'm trying to use Reg Query to review the contents of a registry key.  More precisely

    • HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify

    I just want to know what are the subkeys.  I expect to be

    • IconStreams and
      PastIconsStream

    Since they are both of type reg_binary, when I do this query I have also all binary data as well, make very large output.

    Is there a way to simply retrieve/request which is in the field/column name and not the column/field data ?  I tried the /k options and /v who gave me errors, which I interpreted in the sense I was their use either wrong or they are not used in this instance.

    There is not a lot of examples out there and most of repeat them what you find when you use /?.

    Thank you.

    Hello

    The question you posted would be better suited in the MSDN Forums. I would recommend posting your query in the MSDN Forums.

    http://social.msdn.Microsoft.com/forums/en-us/windowsgeneraldevelopmentissues

  • using reg expression

    I have a table called test with the names of column col1, col2.

    col1 value: 1234. col2 value: 1547

    I need o/p as 14 digits IE common present in the two columns.how to find it using reg expressions.

    Hello

    Here's another way, according to your needs:

    SELECT ename, empno, mgr

    , REGEXP_REPLACE (REGEXP_REPLACE ("0123456789")

    , '[^' || To_char (empno) | ] »

    )

    , '[^' || To_char (mgr). ] »

    ) AS common_digits

    FROM scott.emp

    ORDER BY ename

    ;

    The output does not include duplicate numbers, and the numbers will be in the order 0, 1, 2,..., 9, like this:

    ENAME, EMPNO, MGR COMMON_DIG

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

    7876 7788 78 ADAMS

    7499 7698 79 ALLEN

    7698 7839 789 BLAKE

    7782 7839 78 CLARK

    7902 7566 7 FORD

    7900 7698 79 JAMES

    7566 7839 7 JONES

    KING 7839

    7654 7698 67 MARTIN

    7934 7782 7 MILLER

    7788 7566 7 SCOTT

    SMITH, 7369 7902 79

    7844 7698 78 TURNER

    DISTRICT 7-7698-7521

    You can get the same results without regular expressions, perhaps more effectively.

  • Reg exp to divide the values of the variables

    Hello all, I use Oracle 11.2 of SOE, the value of the variable C is: numberA:numberB for example, C: = ' 1 B: 5 A: 12 has: B: 43 3A ", I have divided than the values of two Variables A and B with the letters of withdrawal and replacement of: for the comma. Namely, the value of each would be: is: 5,12,43 B is: 1.3 someone could help to come up with the correct Exp Reg for this task. Thanks in advance.

    Here's a way (like SQL or PL/SQL):

    with t (Spercu))
    Select "1 B: 5 A: 12 A: B: 43 3A ' double
    )
    Select Spercu
    , regexp_replace (regexp_replace (regexp_replace(strC||':','\d+B:'),' A:$ '), ':', ',') as strA
    , regexp_replace (regexp_replace (regexp_replace(strC||':','\d+A:'),' B:$ '), 'B:', ',') as strB
    ;

    SPERCU STRA, STRB
    ---------------- -------- ------
    1 B: 5 A: 12 A: B: 43 3A 1.3 5,12,43

    or

    declare
    varA varchar2 (30);
    varB varchar2 (30);
    varC varchar2 (30): = ' 1 B: 5 A: 12 A: B: 43 3A;
    Start
    varA: = regexp_replace (regexp_replace (regexp_replace(varC||':','\d+B:'),' A:$ '), ':', ',');
    varB: = regexp_replace (regexp_replace (regexp_replace(varC||':','\d+A:'),' B:$ '), 'B:', ',');
    dbms_output.put_line (Vara);
    dbms_output.put_line (varB);
    end;
    anonymous block filled
    5,12,43
    1, 3

    Replace it after you add a trailing colon varC, Interior removes all the ' nB: "Vara and all the" nA: "from varB. The Middle replace deletes the pair of colon final letter, and replace external converts the other pairs of commas leter-colon.

    Kind regards
    Bob

  • The query options using command exp

    Hello

    I'm trying to export a data tables under the following conditions, but it fails. How to export data from tables with the sub condition? The data type of the column is ID NOT NULL VARCHAR2 (80)

    test/test exp = EMP query = tables------"' where id like ' % 00% ' \ ' log = emp.log file = emp.dmp"

    Export: Release 11.2.0.1.0 - Production Fri Nov 21 21:54:12 2013

    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

    With partitioning, OLAP, Data Mining and Real Application Testing options

    Export in US7ASCII and AL16UTF16 NCHAR character set

    Server uses WE8MSWIN1252 (possible character set conversion) character set

    About to export specified tables by conventional means...

    . . export the table EMP

    EXP-00056: ORACLE 911 error encountered

    ORA-00911: invalid character

    Export completed successfully with warnings.

    The same conditions as the table below mentioned number of records.

    SQL > select count (*) from emp where id like ' % 00% ';

    COUNT (*)

    ----------

    2701

    Kind regards

    007

    PL note that first export is desupported in 11 GR 2 - see the first section of the Note to the Original export

    You should use expdp with the QUERY parameter - Data Pump Export

    HTH
    Srini

  • REG EXP to find if a field starts with a letter

    Hello

    I have a code to clean some phone numbers, and now I want to add a condition to leave the field only if it begins with a letter.

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

    Select

    SR_SERVICE_ID,

    case
    When SR_SERVICE_ID like "% @% ' -does not INCLUDE YEAR ' @' SYMBOL
    then
    SR_SERVICE_ID,
    case
    When SR_SERVICE_ID ' ^ [a-zA-Z] "-STARTS WITH a LETTER (NOT the BODY)"
    then
    SR_SERVICE_ID

    on the other

    '0' || regexp_replace ({SR_SERVICE_ID, ' \D|^0{1} "")-ADD A '0' FOR THE START OF THE FIELD AND GARNISH

    end CLEANSED

    Of
    TABLE_1;

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

    The "SR_SERVICE_ID" field contains email addresses, phone numbers and MOBILE numbers in the format '0400123456'

    I want the script to check if the value of the field begins with a letter or contains a ' @' & ignore them and then go to add a '0' in the field at the start.

    Everything works except the below;

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

    case

    When SR_SERVICE_ID ' ^ [a-zA-Z] "-STARTS WITH a LETTER (NOT the BODY)"

    then

    SR_SERVICE_ID

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

    The problem is that it does not accept the part of the instruction box on the field starting with a letter?

    Can anyone comment why it won't explain all the parts of the Reg Expression they add so I can learn more?

    Thank you

    Hello

    woof777 wrote:

    Thanks again,

    Can you explain what you mean by "then you must only change this WHEN this CASE expression clause.

    I tried everything I can think of, use the instructions box separately & everything is OK, once I add the second back, "Missing Keyword" error.

    I don't see what went wrong the syntax below is just an example, it is not supposed to be correct, just display synatx method.

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

    "case when (expression) then foo .

    -case when (expression) then Do_Something_More

    Else (expression)

    END New_Field_Name ".

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

    Miss me a rule simple syntax here, everything suggests?

    It seemed all you had to do was change a WHEN clause, but unless you post some examples of data in a form usable (for example, CREATE TABLE and INSERT statements) I can't say for sure.

    CASE expressions don't 'do something', or 'do something' in a CASE expression.   What comes after each key word IS a noun, not a verb.  Like all expressions, a CASE expression is something that generates a unique value in a SQL data types; in this case, a VARCHAR2.  After each THEN or ELSE keyword, there must be an expression of the same type.

    After the key words WHEN you have conditions (i.e. operations that result in TRUE, FALSE, or UNKNOWN), not expressions.

    Thus a better model of a CASE expression

    CASE
        WHEN  condition_1  THEN  expression_1
        WHEN  condition_1  THEN  expression_2
                                          ELSE expression_3
    END
    

    If (but only if) the CASE expression is the last part of a column in a SELECT clause, then it can be followed by an alias, such as New_Field_Name.  The alias is the part of the syntax of the SELECT clause; It's completely outside of and independent of the syntax of the CASE expression.

  • How to format a value by using reg expression

    Please, I need to format a value using regular expressions.
    9911223344, 9911223344
    9911223344
      11223344
    Result
    (99) 1122-3344, (99) 1122-3344
    (99) 1122-3344
    1122-3344
    Some tips on how I can do this?

    Kind regards

    Hello

    You were close.
    The first 2 digits are optional, so add a '?' in the model.
    This means that you will get results like ' ((1122-3344'), so use REPLACE to get rid of unwanted brackets.

    SELECT  REPLACE ( REGEXP_REPLACE ( val
                                , '(\d{2})?'     -- ? added here
                               || '(\d{4})(\d{4})'
                                , '(\1) \2-\3'
                         )
              , '() '
              )       AS formatted_val
    FROM    t
    ;
    

    This assumes that "()" does not happen in the raw val. If so, use the REGEXP_REPLACE calls; a search of numbers with eactly 8 digits and the other looking for numbers with exactly 10 digits.

  • Windows XP, using Outlook Exp for emails. Msgs disappeared, including messages in folders.

    Emails and computer turned on have disappeared, including all messages in folders.  How to retrieve messages?

    You should be able to find a solution here.

    http://support.Microsoft.com/kb/321505

  • Question reg exp

    Hello!

    The selection of only printable characters in VARCHAR column?

    Kind regards

    Psmakr
    SQL> SELECT REGEXP_SUBSTR('AS11  sfd' || CHR(7) || 'xx', '[[:print:]]+') FROM dual;
    
    REGEXP_SU
    ---------
    AS11  sfd
    
    SQL>
    
  • 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
    
  • Extraction of the bracketed text string data

    I have a bit of SQL to retrieve the text in brackets at the end of a string:
    WITH test_data AS
         (
         SELECT 'Joseph Bloggs (Joe) (THIS)' v1 FROM DUAL UNION ALL
          SELECT 'Robert Holnas (Bob) (THAT)' FROM DUAL UNION ALL
          SELECT 'Mary Mild (THIS)' FROM DUAL UNION ALL
          SELECT 'Jack Jill (THIS)' FROM DUAL
         )
    SELECT v1
        , INSTR(v1, '(') start_bracket_pos
        , INSTR(v1, ')') end_bracket_pos
        , TRIM(SUBSTR(v1,INSTR(v1, '(')+1,INSTR(v1, ')')-INSTR(v1, '(')-1)) current_label
        , (LENGTH(v1) - LENGTH(REPLACE(v1, ')'))) / LENGTH(')') "ct_("
        , (LENGTH(v1) - LENGTH(REPLACE(v1, ')'))) / LENGTH(')') "ct_)"
      FROM test_data;
    Still, it extracts data from the media at the end of the string.

    I was wondering if I can change it to be able to extract the text between for example two sets of brackets - for the above test data, it would be useful to be able to extract the 'Joe' and 'Bob', but also 'CE' and 'WHO' at the end as well. It would be useful to have a column that contains the first support content and the 2nd set of content in another column.

    Is there a switch that I can use for example an INSTR() to return the position of the first open bracket and the 2nd and so on?

    Any advice much appreciated

    Thank you

    A way, using reg exp:

    SQL> WITH test_data AS
      2       (
      3       SELECT 'Joseph Bloggs (Joe) (THIS)' v1 FROM DUAL UNION ALL
      4        SELECT 'Robert Holnas (Bob) (THAT)' FROM DUAL UNION ALL
      5        SELECT 'Mary Mild (THIS)' FROM DUAL UNION ALL
      6        SELECT 'Jack Jill (THIS)' FROM DUAL
      7       )
      8  SELECT v1
      9      , regexp_substr(v1,'\((.*?)\)',1,1,null,1) bracket1
     10      , regexp_substr(v1,'\((.*?)\)',1,2,null,1) bracket2
     11    FROM test_data;
    
    V1                         BRACKET1                   BRACKET2
    -------------------------- -------------------------- --------------------------
    Joseph Bloggs (Joe) (THIS) Joe                        THIS
    Robert Holnas (Bob) (THAT) Bob                        THAT
    Mary Mild (THIS)           THIS
    Jack Jill (THIS)           THIS
    

    The regular expression find something in parentheses (the? makes not greedy, it's important.)
    1 means start over from the beginning of the string.
    Next number means bracket1 "first occurrence", bracket2 is "second occurrence" - you can continue with 3, 4, etc.
    null value uses only the default options for reg exp (here could be option for example for sensitive cases in search).
    Final 1 means that the result is the first 'group' in the reg exp - this only receives us the text in brackets and not the media themselves.

  • Substitute the inconsistent spacing with a single space in a string

    is it possible to replace multiple spaces in a string with a space only. Number of places is different all the time.

    say a field contains strings with spaces
    I need to replace all those values so that there will be only one space between words.

    For example.
    Input                             Expected Result
    aaa    bbb                       aaa bbb
    ww                vv             ww vv
    ww ss      kk                    ww ss kk
    
    [/code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

    user11253970 wrote:
    I'm in Oracle 9i :( I can't use reg exp

    Assuming that the strings contain no CHR (0) (character with ascii code 0):

    SQL> SELECT  'aaa          bbb  aaa bbb' str,
      2          replace(replace(replace('aaa          bbb  aaa bbb',' ',' ' || CHR(0)),CHR(0) || ' '),CHR(0)) new_str
      3    FROM  dual
      4  /
    
    STR                                 NEW_STR
    ----------------------------------- -----------------------------------
    aaa          bbb  aaa bbb           aaa bbb aaa bbb
    
    SQL> 
    

    SY.

Maybe you are looking for