Question on Substring or Regular Expression

Experts,
I have values is column similar to this:
Remarks:
IHCIS 651216 K6
KORE 657526
COR SWITX 658999 K6 ADHOC
I need to pull out the number starting with "6" (it always starts with 6, and it is always six characters). I then need to set the value of another column to that substring.
Update table x
set p_code = "Query returning the substring value"
I've used substring before but I don't know how to search for the "6" since it is in different locations for each row.
Any help is greatly appreciated.
Rich

Hi,
Here is an example using "SUBSTR':
SQL> select substr('IHCIS 651216 K6', instr('IHCIS 651216 K6', '6') , 6) from dual;
SUBSTR
651216

Similar Messages

  • How to fetch substring using regular expression

    Hi,
    I am new to using regular expression and would like to know some basic details of how to use them in Java.
    I have a String example= "http://www.google.com/foobar.html#*q*=database&aq=f&aqi=g10&fp=c9fe100d9e542c1e" and would like to get the value of "q" parameter (in bold) using regular expression in java.
    For the same example, when we tried using javascript:
    match = example.match("/^http:\/\/(?:(?!mail\.)[^\.]+?\.)?google\.[^\?#]+(?:.*[\?#&](?:as_q|q)=([^&]+))?/i}");
    document.write('
    ' + match);
    We are getting the output as: http://www.google.com/foobar.html#q=database,*database* where the bold text is the value of "q" parameter.
    In Java we are trying to get the value of the q parameter separately or atleast resembles the output given by JavaScript. Please help me resolving this issue.
    Regards
    Praveen

    BalusC wrote:
    Regex is a cumbersome solution for fixed patterns like URL's. String#substring() in combination with String#indexOf would most likely already suffice.I usually agree, although, in this case, finding the exact parameter might be difficult without a small regex, perhaps:
    "\\wq=\\s*"in conjunction with Pattern/Matcher, used similarly to an indexOf() to find the start of the parameter value.
    Winston

  • Searching for a substring using Regular Expression

    I have a lengthy String similar to repetetion of the one below
    String str="<option value='116813070'>Something1</option><option value='ABCDEF' selected>Something 2</option>"I need to search for the Sub string "<option value='ABCDEF' selected>" (need to get the starting index of sub string) and but the value ABCDEF can be anything numberic with varying length.
    Is there any way i can do it using regular expressions(I have no other options than regular expression)?
    thanks in advance.

    If you go through the tutorial then you will find this on the second page:
    import java.io.Console;
    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    public class RegexTestHarness {
        public static void main(String[] args){
            Console console = System.console();
            if (console == null) {
                System.err.println("No console.");
                System.exit(1);
            while (true) {
                Pattern pattern =
                Pattern.compile(console.readLine("%nEnter your regex: "));
                Matcher matcher =
                pattern.matcher(console.readLine("Enter input string to search: "));
                boolean found = false;
                while (matcher.find()) {
                    console.format("I found the text \"%s\" starting at " +
                       "index %d and ending at index %d.%n",
                        matcher.group(), matcher.start(), matcher.end());
                    found = true;
                if(!found){
                    console.format("No match found.%n");
    }It's does everything you need and a bit more. Adapt it to your needs then write a regular expression. Then if you have problems by all means come back and post them up here, but first at least attempt to solve it yourself.

  • SUBSTR or regular expression needed

    Hello,
    I have the below example:
    CREATE TABLE "ARCHITECT"."TEST_DD"
    (     "TABLE_NAME" VARCHAR2(100),
         "APPLICATION_NAME" VARCHAR2(100),
         "COLUMN_NAME" VARCHAR2(100),
         "COLUMN_DESCRIPTION" VARCHAR2(2000)
    ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "MYTABLESPACE"
    i want to have the below result
    CREATE TABLE "ARCHITECT"."TEST_DD"
    (     "TABLE_NAME" VARCHAR2(100),
         "APPLICATION_NAME" VARCHAR2(100),
         "COLUMN_NAME" VARCHAR2(100),
         "COLUMN_DESCRIPTION" VARCHAR2(2000)
    That is mean i want to cut every think after PCTFREE, the above create table is just and example, i may have any create table statement with the PCTFREE keyword
    Please can i have your help

    modify the transform parameters
    SQL> begin
      2     dbms_metadata.set_transform_param(dbms_metadata.session_transform,'STORAGE',false);
      3     dbms_metadata.set_transform_param(dbms_metadata.session_transform,'TABLESPACE',false);
      4     dbms_metadata.set_transform_param(dbms_metadata.session_transform,'SEGMENT_ATTRIBUTES', false);
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select dbms_metadata.get_ddl ('TABLE', 'EMP')
      2    from dual
      3 
    SQL> /
    DBMS_METADATA.GET_DDL('TABLE','EMP')
      CREATE TABLE "SCOTT"."EMP"
       (    "EMPNO" NUMBER(4,0) NOT NULL ENABLE,
            "ENAME" VARCHAR2(10),
            "JOB" VARCHAR2(9),
            "MGR" NUMBER(4,0),
            "HIREDATE" DATE,
            "SAL" NUMBER(7,2),
            "COMM" NUMBER(7,2),
            "DEPTNO" NUMBER(2,0)
    SQL>

  • Regular expression usage question

    Hi there.
    I have a 200 bytes EBCDIC variable record which I need to break down into fields. Fields are positional and are either text, binary numbers, packed-decimal and 64bytes long numbers.
    My question is. Can regular expression handle this complex data.
    I want to isolate each field into their corresponding format. EBCDIC into ASCII text, binary into java Integer and so on.
    The reason for using reqular expression is because the record format could change and regular expression would be easier to modify without having to change the code.
    Your words of advice are highly appreciated.
    Please advice.
    Regards,
    Ulises

    Regular expressions? I don't think so.
    If you have a situation where positions 1-3 might be a binary number like client number, and the format might change so it moves to positions 12-14, then you could certainly write a record-format class to encapsulate that sort of information. In fact that would be a very good idea. But I can't imagine how a regular expression would help in getting a number out of three bytes, for example.

  • Email validation using Regular Expression.

    Hi,
    I am in need of using a regular expression for email valiatino. ^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)$ which is gotten from http://www.regular-expressions.info/email.html .
    This works fine in a regular expression test tool http://regexpal.com/ , but when I use in Oracle, it does not.
    DECLARE
    v_exp VARCHAR2(4000);
    BEGIN
       --v_exp := '^[a-z0-9!#$%&''*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&''*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)$';
       v_exp := '^[a-z0-9!#\$%&''*+/=?\^_`{|}~-]+(?:\.[a-z0-9!#\$%&''*+/=?\^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)$';
       dbms_output.put_line(v_exp);
       FOR v_rec IN (
          with test_data as
    ( select '[email protected]'     as val from dual union all
      select '[email protected]'       as val from dual union all
      select 'ad{[email protected]' as val from dual union ALL
      select '[email protected]' as val from dual union all 
      select '[email protected]' as val from dual union all 
      select '[email protected]'      as val from dual union all
      select 'no#good'                  as val from dual
    select
      val ,
      case
        when
          regexp_like
          (val, v_exp,'i') then 'Y'
        else 'N'
        end
        as good
    from test_data ) LOOP
       dbms_output.put_line(v_rec.val||', '||v_rec.good);
    END LOOP;  
    END;   and the results are
    [email protected], N
    [email protected], N
    ad{[email protected], N
    [email protected], N
    [email protected], N
    [email protected], N
    no#good, N
    The expected result should be Y for all but for the last two.
    I am not sure why it is not working in Oracle.
    Can any body please help me to find the mistake and to have it correctly?
    Advance Thanks,
    Natarajan
    Edited by: Nattu on Dec 4, 2012 1:31 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Try this regular expression:
    >> ^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$
    >> [email protected], *Y*
    >> [email protected], *Y*
    >> ad{[email protected], N
    >> [email protected], *Y*
    >> [email protected], *Y*
    >> [email protected], N
    >> no#good, N
    [Using a regular expression to validate an email address|http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address]
    Edited by: stefan nebesnak on 4.12.2012 2:25                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Question about match regular expression

    Colleagues,
    Very stupid question. I would like to get substring between "..." symbols. For example, string 02 July from Explosion occurred on "02 July", 2008.
    How to do this with single Match Regular Expression?
    For example such expression ".*" will give me "02 July":
    But I would like to get it without " symbols!
    I tried this "[~"]*" and this "[~"].*", then read this and this , and all without success... But I'm sure it should be possible. Can you help me?
    Andrey.
    PS
    This regular expression should give exactly the same output as following construction:

    I'm only using 7.0 now, but you can do this with Scan from String...
    %[^"]"%[^"]"%[^"]
    Message Edited by Phillip Brooks on 07-02-2008 02:47 PM
    Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
    If you don't hate time zones, you're not a real programmer.
    "You are what you don't automate"
    Inplaceness is synonymous with insidiousness
    Attachments:
    NotPCRE.png ‏20 KB

  • Regular Expressions - Questions to SME

    Ralph Benzinger presented an online meetup on the topic of Regular Expressions.  The presentation (slides only) can be found <a href="http://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/866072ca-0b01-0010-54b1-9c02a45ba8aa">here</a>
    Unfortunately the recording is not going to be available, but Ralph has been generous enough to agree to answer questions posted to this sticky thread.
    cheers,
    Marilyn

    Hello Peter,
    You're welcome!
    Alas, I was unable to locate the regex documentation on help.sap.com either.  In fact, I'm not even sure it has already been updated for 2004s.  I recommend that you use the online documentation within the system, e.g., from transactions SE38 or SE80.  Do an index search for "regex", and you'll be directed to REGEX, FIND and REGEX, REPLACE, both of which have extensive subsections on regexes.
    The class cx_sy_regex is an exception class that is thrown by FIND, REPLACE and cl_abap_regex in case of an invalid regex, such as ".\1" (there is no capture group that back reference \1 can refer to).  If the pattern is known statically, the syntax check will report this error, but for statements like "FIND REGEX pat IN text.", the actual pattern is only known at runtime.
    The cx_sy_matcher class (and its subclasses) similarly indicate some invalid states, for example trying to call "cl_abap_matcher->replace_found( )" when the matcher has no current match to replace (e.g., replace_found( ) called twice in a row).
    Please let me know if I can provide some additional information.
    Regards
    Ralph

  • Regular expression for 2nd occurance of a substring in a string

    Hi,
    1)
    i want to find the second occurrence of a substring in a string with regular expression so that i can modify that only.
    Ex: i have a string like ---> axe,afn,sdk,jdi,afn,mki,mki
    in this i want the second occurance of afn and change that one only...
    which regular expression i have to use...
    Note that ...i have to use regular expression only....no string manipulation methods...(strictly)
    2)
    How can i apply the multiple regular expressions multiple times on a single string ..i.e in the above instance i have to apply the same 2nd occurrence logic for
    substring mki also. for this i have to use a single regular expression string that contains validations for both the sub strings mki and afn.
    Thanks in advance,
    Venkat

    javafreak666 wrote:
    Hi,
    1)
    i want to find the second occurrence of a substring in a string with regular expression so that i can modify that only.
    Ex: i have a string like ---> axe,afn,sdk,jdi,afn,mki,mki
    in this i want the second occurance of afn and change that one only...
    which regular expression i have to use...
    Note that ...i have to use regular expression only....no string manipulation methods...(strictly)
    2)
    How can i apply the multiple regular expressions multiple times on a single string ..i.e in the above instance i have to apply the same 2nd occurrence logic for
    substring mki also. for this i have to use a single regular expression string that contains validations for both the sub strings mki and afn.
    Thanks in advance,
    VenkatWhat do you mean by using a regex to get the index of a second substring? There is not method in Java which uses regex to et the index of a substring.
    There are various indexOf(...) methods for this:
    String text = "axe,afn,sdk,jdi,afn,mki,mki";
    String target = "afn";
    int second = text.indexOf(target, text.indexOf(target)+1);
    System.out.println("second="+second);Of course you can find the index of a group like this:
    Matcher m = Pattern.compile(target+".*?("+target+")").matcher(text);
    System.out.println(m.find() ? "index="+m.start(1) : "nothing found");but there is not single method that handles this: you'll have to call the find() and then the start(...) method on the Matcher instance, so the indexOf(...) approach is the favourable one, IMO.

  • Jakarta regular expression package question

    hi everyone,
    I'm trying to figure out how to use the jakarta regular expression package to return an array of matches ?
    For example let's say i had StringBuffer object consisting of say 30,000 characters and I needed to return all the matches that started with < and ended with > (like all the xml tags )
    anybody know how I could use the package to return an array of matches ?
    thanks in advance
    stev

    okay -- perhaps i should maybe rephrase my question for this package -- perhaps it is more popular ?
    anyone know how i can pass a regular expression to it and retrieve a String array
    In my specific situation , I have a StringBuffer with about 10,000 characters in it ?
    any ideas how i would use regular expressions to look through this Stringbuffer object
    thanks
    stephen

  • Help: Regular Expression question??

    Hello,
    How can I extract the following content using Java Regular expression?
    <tr bgcolor="#333333">
         <td class="title" colspan="4" height="18"> <b>SUPER_1</b> - SUPER_2</td>
    </tr>
    <tr bgcolor="#333333">
         <td class="match-light" width="45" height="18"> </td>
         <td class="match-light" colspan="3" width="286" align="right">March 19 </td>
    </tr>
    <tr>
         <td colspan="4" height="1"></td>
    </tr>
    <tr bgcolor="#cfcfcf">
         <td width="45" height="18"> FT</td>
         <td width="118" align="right">SUPER_3</td>
         <td width="50" align="center"><a class="scorelink" target="details" onclick="showDetails();">999 - 888</a></td>
         <td width="118">SUPER_4</td>
    </tr>From the above contents, How can I define a regular expression for extract the "*SUPER_1*", "*SUPER_2*", "*March 19*", "*SUPER_3*", "*999*", "*888*" and "*SUPER_4*" ????
    Please help.
    Best regards,
    Eric

    Kayaman wrote:
    Why not use a better way than regex, like an actual HTML parser (or XML if you have it well-formed)? People seem to love parsing (or rather, asking help how to parse) HTML with regex for some unknown reason.Indeed.
    Read this (hilarious):
    http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454

  • Regular Expression Question

    Hi all,
    I am suffering in java regular expression, and I hope you guys can help me out. I want to use the String api ".matches" to find out any string pattern like "xxxx.xxxx" where xxx can be only english word(both upper and lower case). Actually I will use this kind of expression to represent the cross join SQL statement in my java class, like "tableA.name = tableB.name", where they should be english letter only. I tried to use MyString.matches("^[A-Z] + \\. + ^[A-Z]") in my java program, but seem it doesn't work. Can you guys figure out the right expression for me ?? Many thanks
    Transistor

    Thanks for your prompt response, I tried your code, however, it doesn't work out.
    I put your code like the following:
    if ( searchCriteria.getStringPair().getValue().trim().matches("[A-Za-z]+\\.[A-Za-z]+") {...some action }.
    Seems the java program never reach this expression.
    Kindly remind that I wan to expression anything like "xxxxx.xxxxx" where xxxx can be a word.
    Myriads of thanks
    Transistor

  • Regular Expression Question, Repetition Operators

    These are my success entries for a field;
    123456,
    123456,123456,
    123456,123456,123456,
    123456,123456,123456,123456,
    "," seperated 6 digits can be repeated unlimited times.
    I found on documentation this; "Repetition Operators; {m,}     Match at least m times" and for my need i tried this regular expression; "^[[[:digit:]]{6},]{1,}$", but didnt worked :(
    Any comments?
    Thank you very much :)
    Tonguc

    repeating exactly 6
    {6}
    repeating at least 1
    +
    repeating at least 6
    {6,}
    ok, your problem is [ instead of (                                                                                                                                                                                                                                                    

  • Regular Expression question I think

    My application is receiving HTML as a string and I'm trying to simplify it before displaying. The string could contain one or more substrings similar to this:
    <span style="cursor:pointer" onmouseout="hideTooltip()" onmouseover="createTooltip( this,'The quartile that your firm\'s value falls into.  Each quartile contains 25% of the values in the Peer Group. The 1st Quartile is always the best.  The 4th Quartile is always the worst.', ( findPosX( this ) - 150))">Quartile</span>The text will not be consistent and it may be in the string as many as 4 times. What I'd like to do is replaceAll so that I end up with
    <span>Quartile</span>Is there a way to do this with regular expression? I've tried replaceAll("<span .*>","<span>") But that takes out everything to the end of the String. I want it to stop at >.
    Any way?

    replaceAll("<span .*?>","<span>")

  • Regular expression question (should be an easy one...)

    i'm using java to build a parser. im getting an expression, which i split on a white-space.
    how can i build a regular-expression that will enable me to split only on unquoted space? example:
    for the expression:
    (X=33 AND Y=44) OR (Z="hello world" AND T=2)
    I will get the following values split:
    (X=33
    AND
    Y=34)
    OR
    (Z="hello world"
    AND
    T=2)
    and not:
    (Z="
    hello
    world"
    thank you very much!

    Instead of splitting on whitespace to get a list of tokens, use Matcher.find() to match the tokens themselves: import java.util.*;
    import java.util.regex.*;
    public class Test
      public static void main(String[] args) throws Exception
        String str = "(X=33 AND Y=44) OR (Z=\"hello world\" AND T=2)";
        List<String> tokens = new ArrayList<String>();
        Matcher m = Pattern.compile("[^\\s\"]+(?:\".*?\")?").matcher(str);
        while (m.find())
          tokens.add(m.group());
        System.out.println(tokens);
    }{code} The regex I used is based on the assumptions that there will be at most one run of quoted text per token, that it will always appear in the right hand side of an expression, and that the closing quote will always mark the end of the token.  If the rules are more complicated (as sabre150 suggested), a more complicated regex will be needed.  You might be better off doing the parsing the old-fashioned way, with out regexes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for