Regular expression in FIND statement

Hi All,
I am writing the regular expressions.
But i didn't get properly how to write them.
I have one internal table with the five fields.
Exapmle wa-mandt = '800'.
             wa_number = '3768'
             wa_path = '/usr/tmp/sapuser/3768/test.txt.'
append wa to itab.
Loop at itab itno wa.
Here i need to find client and number system id from the WA using regular expression in singe line
endloop.
Can anybody please explain how to write this.
Thanks,

Hi,
What do you mean by FIND?
If I got it right, you can use a READ statement with KEY f1 f2 etc BINARY SEARCH.Mention all the fields you want in the KEY fields.
Dont forget to SORT this itab before the loop.
Thanks
Kiran

Similar Messages

  • How to write regular expression to find desired string piece *duplicate*

    Hi All,
    Suppose that i have following string piece:
    name:ali#lastname:kemal#name:mehmet#lastname:cemalI need
    ali
    mehmetI use following statement
    SQL> select lst, regexp_replace(lst,'(name:)(.*)(lastname)(.*)','\2',1,1) nm from (
      2    select 'name:ali#lastname:kemal#name:mehmet#lastname:cemal' as lst from dual
      3  );
    LST                                                NM
    name:ali#lastname:kemal#name:mehmet#lastname:cemal ali#lastname:kemal#name:mehmet#
    SQL> But it does not return names correctly. When i change 5th parameter(occurence) of regexp_replace built-in function(e.g. 1,2), i may get ali and mehmet respectiveley.
    Any ideas about regexp?
    Note : I can use PL/SQL instr/substr for this manner; but i do not want to use them. I need regexp.
    Regards...
    Mennan
    Edited by: mennan on Jul 4, 2010 9:53 PM
    thread was posted twice due to chrome refresfment. Please ignore the thread and reply to How to write regular expression to find desired string piece

    The approach is to do cartesian join to a 'number' table returning number of records equal to number of names in the string.I have hardcoded 2 but you can use regexp_count to get the number of occurrences of the pattern in the string and then use level <=regexp_count(..... .
    See below for the approach
    with cte as(
    select
    'name:ali#lastname:kemal#name:mehmet#lastname:cemal' col ,level lev
    from dual connect by level <=2)
    select substr(regexp_substr('#'||col,'#name:\w+',1,lev),7)
    from cte
    /

  • Unable To Use Regular Expression To Find Function Names

    Hi,
    I am trying to create a regular expression to find function and procedure names without the static designation and the parameter list.  Sample source document:
    static function test
    static function test(i,j)
    function test
    function test(i,j)
    static procedure test
    static procedure test(i,j)
    procedure test
    procedure test(i,j)
    For each of the above samples, I would like only the word "test" to be found.
    Thanks

    I suggest starting with this expression:
    ^\s*(static\s+)?(function|procedure)\s+(?<NAME>\w+)
    Programmatically, the name can be extracted from the group called “NAME”.
    The expression can be improved.

  • Regular Expression for finding Latin characters

    i have a table "t" with values in column "text" like
    "Āniki"
    "Ąvatar"
    How can I find them using a regular expression?
    The real goal is to replace them with their ASCII equivalent.
    Ā = A
    Č = C
    Ĥ = H
    etc....

    You can set any range in the ascii table by using the expression 'X-Y' in the pattern. It works for symbols too, but you need to find out whether the desired characters you're interested actually form a contiguous range.
    You can run the below query to check the ascii table:
    SELECT LEVEL ascii_val, chr(LEVEL) chr_column FROM dual CONNECT BY LEVEL < 256;Then you can pick and choose your ranges and verify them as in the following query:
    WITH t AS
    (SELECT LEVEL ascii_val, chr(LEVEL) chr_column FROM dual CONNECT BY LEVEL < 256)
    SELECT ascii_val, chr_column FROM t WHERE regexp_like(chr_column, '[^A-Za-z0-9!-/]');In the example above I chose a range from the ascii 33 ('!') to 47 ('/'), described by the portion '!-/' in the pattern.
    To add another range just concatenate it after the slash symbol.
    Additionally, for example, if you want to add a range including the symbols:
    ASCII CHR
    58    :
    59    ;
    60    <
    61    =
    62    >
    63    ?You can set it up like this instead if you feel it's more easily readable:
    WITH t AS
    (SELECT LEVEL ascii_val, chr(LEVEL) chr_column FROM dual CONNECT BY LEVEL < 256)
    SELECT ascii_val, chr_column
      FROM t
    WHERE regexp_like(chr_column, '[^A-Za-z0-9' ||
                                   chr(33) || '-' || chr(47) ||
                                   chr(58) || '-' || chr(63) ||
                                   ']');You need to test this though, as the docs state the behaviour may vary depending on your NLS_SORT settings, by using linguistic ranges rather than byte values. For my settings it seems to work, not sure about everywhere else.
    Note: In the POSIX standard, a range includes all collation elements between the start and end of the range in the linguistic definition of the current locale. Thus, ranges are linguistic rather than byte values ranges; the semantics of the range expression are independent of character set. In Oracle Database, the linguistic range is determined by the NLS_SORT initialization parameter.http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_regexp.htm
    and
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10729/ch5lingsort.htm
    You can check your NLS_SORT by querying the userenv:
    SQL> select sys_context('USERENV', 'NLS_SORT') from dual;
    SYS_CONTEXT('USERENV','NLS_SOR
    WEST_EUROPEAN
    SQL> If it returns BINARY you need not worry about it.
    Otherwise you can check the particular sorting your NLS_SORT will use here:
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10729/applocaledata.htm#NLSPG593
    Usually symbols are not affected by it as you can see there (my case too for the "west_european" value), but other elements in a string can be affected.
    Regards,
    Sitja.
    Edited by: fsitja on Mar 18, 2010 1:51 PM

  • Help with regular expression to find a pattern in clob

    can someone help me writing a regular expression to query a clob that containts xml type data?
    query to find multiple occurrences of a variable string (i.e <EMPID-XX> - XX can be any number). If <EMPID-01> appears twice in the clob i want the result as EMPID-01,2 and if EMPID-02 appears 4 times i want the result as EMPID-02,4.

    with
    ofx_clob as
    (select q'~
    <EMPID>1
    < UNQID>123456
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    <EMPID>2
    < UNQID>123457
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    <EMPID>1
    < UNQID>123458
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    ~' ofx from dual
    select '<EMPID>' || to_char(ids) || '(' || to_char(count(*)) || ')' multi_empid
      from (select replace(regexp_substr(ofx,'<EMPID>\d*',1,level),'<EMPID>') ids
              from ofx_clob
            connect by level <= regexp_count(ofx,'<EMPID>')
    group by ids having count(*) > 1
    MULTI_EMPID
    <EMPID>1(2)
    with
    ofx_clob as
    (select q'~
    <EMPID>1
    < UNQID>123456
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    <EMPID>2
    < UNQID>123457
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    <EMPID>1
    < UNQID>123456
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    <EMPID>2
    < UNQID>123456
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    <EMPID>1
    < UNQID>123458
    < TIMESTAMP>...
    < ADDRINFO>
    < TITLE>^@~*
    < FIRST>ABCD
    < MI>
    < LAST>EFGH
    < ADDR1>ADDR1
    < ADDR2>^@~*
    < CITY>CITY
    ~' ofx from dual
    select '<EMPID>' || listagg(to_char(ids) || '(' || to_char(count(*)) || ')',',') within group (order by ids) multi_empid
      from (select replace(regexp_substr(ofx,'<EMPID>\d*',1,level),'<EMPID>') ids
              from ofx_clob
            connect by level <= regexp_count(ofx,'<EMPID>')
    group by ids having count(*) > 1
    MULTI_EMPID
    <EMPID>1(3),2(2)
    Regards
    Etbin
    Message was edited by: Etbin
    used listagg to report more than one multiple <EMPID>

  • Using regular expressions to find and replace code.

    Hi! Semi-newbie coder here.
    I'm trying to strip out code from multiple pages, I've tried regular expressions but I'm struggling to understand them. I also need to do it across a LOT of pages, so I need an automated way of doing it.
    The best way I can explain is with an analogy:
    I want to delete any string of characters that start with c, ends with t and includes anything inbetween, so it would pick up "cat, cut, chat, coconut, can do it" whatever appears in the middle of those.
    Except, instead of c and t, I want it to find strings of code starting with <div class="advert" and ending with Vote<br> while picking up everything in between, (including spaces, code, comments, etc.). Then, deletes that whole string including the starting and ending.Is there a regular expression I could use in dreamweaver that could do this? Is there a way to do this at all?

    Let me begin by saying I'm a complete idiot with DW's Reg Ex.   I use Search Specific Tag whenever possible.  See screenshot below.
    Try this on your Current Document to see if it works. Then make a back-up copy of site before attempting it on Entire Local Site as you cannot "Undo" this process.
    Good luck,
    Nancy O.

  • Using Regular Expressions to Find Quoted Text

    I have run into a couple problems with the following code.
    1) Slash-Star and Slash-Slash commented text must be ignored.
    2) It does not detect backslashed quotes, or if that backslash is backslashed.
    Can this be accomplished with Regular Expressions, or should I implement this using if/indexOf logic?
    Thank You in advance,
    Brian
        * Finds position of next quoted string in a line
        * of source code.
        * If no strings exist, then a Pointer position of
        * (0,0) is returned.
        * @param startPos position to start search from
        * @param argText  the line of text to search
        * @returns next string position
       public Pointer getQuotedStringPosition(int startPos, String aString) {
          String argText = new String( aString );
          Pattern p = Pattern.compile("[\"][^\"]+[\"]");
          Matcher m = p.matcher( argText.substring(startPos); );
          if( m.find() )
             return new Pointer( m.start() + startPos, m.end() + startPos );
          else
             return new Pointer( 0, 0 ); // indicates nothing was found
       }

    YATArchivist was right about the regular expressions.
    I think I've got it but somebody test it if you want. Let me know what you find.
    I've included a barebones Position class as well...
    import java.util.regex.*;
    import java.io.*;
    import java.util.*;
      @author Joshua A. Logan, Jr.
    public class RegexTest
       private static final String SLASH_SLASH = "(//.*)";
       private static final String SLASH_STAR =
                               "(/\\*(?:[^\\*]|(?:\\*(?!/)))+(\\*/)?)";
       private static final Pattern COMMENT_PATTERN =
                         Pattern.compile( SLASH_SLASH + "|" + SLASH_STAR );
       private static final Pattern QUOTED_STRING_PATTERN =
                      Pattern.compile( "\"  ( (?:(\\\\.) | [^\\\"])*+  )     \"",
                                       Pattern.COMMENTS );
       // Breaking the above regular expression down, you'd have:
       //   "  ( (?: (\\ .)  |  [^\\ "]  ) *+ )   "
       //   ^          ^     ^     ^       ^      ^
       //   |          |     |     |       |      |
       //   1          2     3     4       5      6
       // which matches:
       // 1) The starting quote...
       // Followed by something that is either:
       // 2) some escaped sequence ( e.g. _\n_  or even _\"_ ),
       // 3)                ...or...
       // 4) a character that is neither a _\_ nor a _"_ .
       // 5) Keep searching this as much as possible, w/o giving up
       //                    any found text at the end.
       //        Note: the text found would be in group(1)
       // 6) Finally, find the ending quote!!
       public static Position [] getQuotedStringPosition( final String text )
          Matcher cm = COMMENT_PATTERN.matcher( text ),
                  qm = QUOTED_STRING_PATTERN.matcher( text );
          final int len = text.length();
          int startPos = 0;
          List positions = new ArrayList();
          while ( startPos < len )
             if ( cm.find(startPos) )
                int commStart = cm.start(),
                    commEnd   = cm.end();
                // are we starting @ a comment?
                if ( commStart == startPos )
                   startPos = commEnd;
                else if ( qm.find(startPos) )
                   // Search for unescaped strings in here.
                   int stringStart = qm.start(1),
                       stringEnd   = qm.end(1);
                   // Is the quote start after comment start?
                   if ( stringStart > commStart )
                      startPos = commEnd; // restart search after comment end...
                   else if ( (stringEnd > commEnd) ||
                             (stringEnd < commStart) )
                      // In this case, the "comment" is actually part of
                      // the quoted string. We found a match.
                      positions.add( new Position(text, qm.group(1),
                                                  stringStart,
                                                  stringEnd) );
                      int quoteEnd = qm.end();
                      startPos = quoteEnd;
                   else
                      throw new IllegalStateException( "illegal case" );
                else
                   startPos = commEnd;
             else
                // no comments were found. Search for unescaped strings.
                int quoteEnd = len;
                if ( qm.find( startPos ) ) {
                   quoteEnd = qm.end();
                   positions.add( new Position(text,
                                               qm.group(1),
                                               qm.start(1),
                                               qm.end(1)) );
                startPos = quoteEnd;
          return positions.isEmpty() ? Position.EMPTY_ARRAY
                                     : (Position[])positions.toArray(
                                              Position.EMPTY_ARRAY);
       public static void main( String [] args )
          try
             BufferedReader br = new BufferedReader(
                      new InputStreamReader(System.in) );
             String input = null;
             final String prompt = "\nText (q to quit): ";
             System.out.print( prompt );
             while ( (input = br.readLine()) != null )
                if ( input.equals("q") ) return;
                Position [] matches = getQuotedStringPosition( input );
                // What does it do?
                for ( int i = 0, max = matches.length; i < max; i++ )
                   System.out.println( "-->" + matches[i] );
                System.out.print( prompt );
          catch ( Exception e )
             System.out.println ( "Exception caught: " + e.getMessage () );
    class Position
       public Position( String target,
                        String match,
                        int start,
                        int end )
          this.target = target;
          this.match = match;
          this.start = start;
          this.end = end;
       public String toString()
          return "match==" + match + ",{" + start + "," + end + "}";
       final String target;
       final int start;
       final int end;
       final String match;
       public static final Position [] EMPTY_ARRAY = { };
    }

  • "Multiple Line" Regular expressions in find/replace

    Hi there,
    I'm wondering if it is possible to find and replace (in batch
    mode) the following obstacle:
    say is have this piece of code in every html file i'd like to
    edit:
    <html>
    <blah blah (Same text in all files)>
    <blah blah (NOT same text in all files)>
    <blah blah (NOT same text in all files)>
    <code that is the same again in all files>
    and would like to replace it by nothing, effectively deleting
    the part completely... (by leaving the replace by field empty).
    The tricky part is that the lines which are NOT the same in
    all files, are sometimes 2 lines, but sometimes 3 or more lines.
    Somehow I need to get the regular expression to include
    <line>* (or something similar), in order to make the regular
    expression work.
    Any ideas on how to solve this? I must say untill now, the
    Dreamweaver search and replace function has been the most effective
    one, compared to many alternatives out there.
    Rp

    I've tried \1 and $1Just these in the text items of the find & replace dialog box...?????
    Can you write down exactly what have you tried....(text to be replaced by which....)????
    Greetings....
    Sim

  • How to use regular expression to find string

    hi,
    who know how to get all digits from the string "Alerts 4520 ( 227550 )  (  98 Available  )" by regular expression, thanks
    br, Andrew

    Liu,
    You can use RegEx as   
    d+
    Whether you are using CL_ABAP_REGEX class then
    report  zars.
    data: regex   type ref to cl_abap_regex,
          matcher type ref to cl_abap_matcher,
          match   type c length 1.
    create object regex exporting pattern = 'd+'
                                  ignore_case = ''.
    matcher = regex->create_matcher( text = 'Test123tes456' ).
    match = matcher->match( ).
    write match
    You can find more details regarding REGEX and POSIX examples here
    http://www.regular-expressions.info/tutorial.html

  • Regular Expression.  Select Statement.  Carriage Return

    Oracle 9i
    Using SQLPLUS
    I've read about regular expression and need some translation/explanation.
    I have a large table containing a varchar2 (free text) column. Users may have inserted carriage returns when they entered the data. I need to locate rows that contain carriage returns, select and display them. Later I'll need to update those rows to replace the carriage returns with a space.
    Can you assist with syntax. I believe use of a regular expression is required.
    Thanks

    for single characters like <CR> TRANSLATE() Doh. Never post at the end of a long day.
    As the other posters have pointed out, one-for-one single character substitution is normally done with REPLACE(), although TRANSLATE() also works. The more normal role for TRANSLATE() is situations where you want to substitute multiple characters, e.g.
    SQL> update <your table> set <your column> = replace (<your column> , chr(13)||chr(10), ' ');This substitutes a space for a carriage return and line feed combination.
    Cheers, APC

  • How to find a regular expression in a statement

    I have to find regex in a statement and return boolean true if it matches .
    regexpression : AR%SUPERUSER
    How to write in code?
    I have tried this
    String EXAMPLE_TEST = "This is my AR SUPERUSER string which I'm going to use for pattern matching.";
    System.out.println(EXAMPLE_TEST.matches("AR SUPERUSER"));
    It returned false

    That works fine, but if you want to find the part of the String you have some options:
    String EXAMPLE_TEST = "This is my small example string which I'm going to use for pattern
    System.out.println(EXAMPLE_TEST.matches(".+small example.+"));
    System.out.println(EXAMPLE_TEST.indexOf("small example") >= 0);
    System.out.println(EXAMPLE_TEST.contains("small example"));{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to write regular expression to find desired string piece

    Hi All,
    Suppose that i have following string piece:
    name:ali#lastname:kemal#name:mehmet#lastname:cemalI need
    ali
    mehmetI use following statement
    SQL> select lst, regexp_replace(lst,'(name:)(.*)(lastname)(.*)','\2',1,1) nm from (
      2    select 'name:ali#lastname:kemal#name:mehmet#lastname:cemal' as lst from dual
      3  );
    LST                                                NM
    name:ali#lastname:kemal#name:mehmet#lastname:cemal ali#lastname:kemal#name:mehmet#
    SQL> But it does not return names correctly. When i change 5th parameter(occurence) of regexp_replace built-in function(e.g. 1,2), i may get ali and mehmet respectiveley.
    Any ideas about regexp?
    Note : I can use PL/SQL instr/substr for this manner; but i do not want to use them. I need regexp.
    Regards...
    Mennan

    Hi, Mennan,
    You can nest REGEXP_SUBSTR withing REGEXP_REPLACE to get the n-th occurrence, like this:
    SELECT     lst
    ,      REGEXP_REPLACE ( REGEXP_SUBSTR ( lst
                                      , 'name:[^#]*#lastname'
                               , 1
                               , n
                     , 'name:(.*)#lastname'
                     , '\1'
                     )      AS nm If the pattern occurs fewer than n times, the expression above returns NULL.

  • Issues regular expression for "find all" feature

    Hi,
    I am currently working on a website in dreamweaver that
    contains about 2000 pages. I know some of these pages are missing a
    div called id="breadcrumb". I have tried to find a way to search in
    the "entire current local website" for pages that do not contain
    any div with the id="breadcrumb". However, it does not seem to
    work, I tried using the {n} syntax as {0} but it doesn't return
    anything I expect, which is pages that do not contain
    id="breadcrumb".
    Thanks for your help.
    Loic

    > I am currently working on a website in dreamweaver that
    contains about
    > 2000
    > pages. I know some of these pages are missing a div
    called
    > id="breadcrumb". I
    > have tried to find a way to search in the "entire
    current local website"
    > for
    > pages that do not contain any div with the
    id="breadcrumb". However, it
    > does
    > not seem to work, I tried using the {n} syntax as {0}
    but it doesn't
    > return
    > anything I expect, which is pages that do not contain
    id="breadcrumb".
    An option:
    Is this div normally next to another unique HTML element on
    the page that is
    in all pages? Like this:
    <div id="xyz">
    <div id="breadcrumb">
    If so, you could to a find for:
    <div id="xyz">
    and replace with:
    <div id="xyz">
    <div id="breadcrumb">
    Then, since the pages that already had the breadcrumb div
    would now have
    both, you do a second search and replace to remove the
    duplicates:
    find:
    <div id="breadcrumb">
    <div id="breadcrumb">
    replace:
    <div id="breadcrumb">
    Of course, you'd still have to worry about the closing
    </div> tag and that
    might get tricky.
    Ultimately, though, a site with 2000 pages really is a likely
    candidate for
    a migration into a CMS instead of manually having to maintain
    individual
    HTML files like this.
    -Darrel

  • Java – Regular Expressions – Finding any non digit byte in a multiple byte

    Hello,
    I’m new to JAVA and Regular Expressions; I’m trying to write a regular expression that will find any records that contain a non digit byte in a multiple byte field.
    I thought the following was the correct expression but it is only finding records that contain “all” non digit bytes.
    \D{1,}
    \D = Non Digit
    {1,} = at least 1 or more
    Below is my sample data. I would like the regular expression to find all of the records that are not all numeric. However when I use the regular expression \D{1,} it is only finding the 2 records that all bytes are non digits. (i.e. “ “ and “A “)
    “ 111229”
    “2 111229”
    “20091229”
    “200912c9”
    “201#1229”
    “20101229”
    “20110229”
    “20111*29”
    “20111029”
    “20111229”
    “20B11229”
    “A “
    “A0111229”
    Please note I have also tried \D{1,}+ and \D{1,}? And they also do not return my desired results
    Any assistance someone can provide would be greatly appreciated.

    You don't show the code you are using but I surmise you are using String.matches() which requires that the whole target must match the regular expression not just part of it. Instead you should create a Pattern and then a Matcher and use the Matcher.find() method. Check the Javadoc for Pattern and Matcher and look at the Java regex tutorial - http://docs.oracle.com/javase/tutorial/essential/regex/ .
    P.S. You can re-use the Pattern object - you don't have to create it every time you need one.
    P.P.S. Java regular expressions work with characters not bytes and characters are not not not bytes.

  • Regular Expression - find double hyphens only

    I am wondering if there's a way to write a regular expression to find double hyphens and change them to single hyphens.  The catch is that some of the text I'm searching through have multiple hyphens.
    Example:
    str1 = "Here is my sample text with double -- and I would like to replace this with one hyphen."
    str2 = "Here is another sample with multiple hyphens ----- that I do not want to change but leave as is."
    Is there a way to change only str1 to a single hyphen and keep str2 as is?

    You are correct.  I should have been more explict.  Here are some real examples.  I hope this helps.
    Helps what?
    Have you tried to write the regex yourself, at least?
    Adam

Maybe you are looking for