REG EXP pattern ?

Hi Folks;
I need to create a reg exp pattern with these rules :
mpexprfinal      : mpexprUnit(\ OROP\ mpexprUnit)*
mpexprUnit      : mp(\ AND\ mp)*minusplusexpr
minusplusexpr :     "\ \(+\)\ " or "\ \(-\)\ "
mp : "[A-Z]{1}[0-9]{6}" (ex: I123456)
OROP : ","
Help me please!
Edited by: Moostiq on 2 mai 2011 16:52
Edited by: Moostiq on 2 mai 2011 16:52

Hi,
I don't know of any really good way to assign names to sub-patterns in a regular expression, and then use those names in bigger expressions.
You can (sort of) do the same thing in SQL, by assigning column aliases to string literals (as in def_1, below), or concatentions of literals and previouslly defined aliases (as in def_2):
WITH     def_1         AS
     SELECT     '\(\+|-\)'          AS minusplusexpr
     ,     '[A-Z]{1}[0-9]{6}'     AS mp
     ,     ';'               AS orop
     FROM     dual
,     def_2        AS
     SELECT  def_1.*
     ,     mp || '( AND '
             || mp
             || ')*'          AS mpexprunit
     FROM    def_1
SELECT     x.*
FROM          table_x     x
CROSS JOIN     def_2     d
WHERE     REGEXP_LIKE ( x.txt
              , d.mpexprunit || '('
                             || d.orop
                       || '|'
                       || d.mpexprunit
                       || ')*'
;Take this as pseudo-code. I'm not sure it will do anything. (I can't test it until you post some sample data).
If it does run, I'm not sure it will do what you want (since you haven't explained what you want).
You may find it easier just to repeat the expressions in your code. An approach like the one above is most useful when the definitions (mp, mpexprunit, and so on) change frequently.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using. I'm not sure you'll need any features that were added after Oracle 10.1, but why take a chance?

Similar Messages

  • Reg Exp won't make a match with metacharacters?

    Hi All,
    I'm trying to implement a filefilter using regular expressions to allow wildcard searches. Here is the code I have so far. Works fine for a literal match, but if i enter a wildcard search (eg. abc123) it will not list any files, even though if I enter the full name for a file, it matches just fine. Anyone got any ideas because I'm just comming up blank?
    thanks!
    package dbmanager2;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.regex.*;
    * @author nkelleh
    public class LotDialog
        // Declare variables
        private String[] dirFiles;
        // Class constructor
        public LotDialog(String path, String name)
            // Create new file object based on path name given
            File dir = new File(path);
            // Assign file names to string array
            dirFiles = dir.list(new stdfFilter(name));
        public void printFiles()
            for (String files : dirFiles)
                System.out.println("File is " + files );
        class stdfFilter implements FilenameFilter {
            Pattern pattern;
            public stdfFilter(String search)
                // Replace wildcard, '*', with reg exp, '.*'
                search = search.replaceAll("\\*", ".*");
                search = search.replaceAll("\\?", ".");
                pattern = Pattern.compile(search);
                System.out.println(pattern.pattern());
            public boolean accept(File dir, String name)
                if (new File(dir,name).isDirectory())
                    return false;
                else
                    // Return true if a match is found
                    Matcher matcher = pattern.matcher(dir.getName());
                    return matcher.matches();               
    }

    LeWalrus wrote:
    Hi All,
    I'm trying to implement a filefilter using regular expressions to allow wildcard searches. Here is the code I have so far. Works fine for a literal match, but if i enter a wildcard search (eg. abc123) it will not list any files, even though if I enter the full name for a file, it matches just fine. Anyone got any ideas because I'm just comming up blank?
    ...Try debugging your code. A good place to start is to print the following to see where things go wrong:
    public boolean accept(File dir, String name)
      if (new File(dir,name).isDirectory())
        System.out.println("Ignoring: "+new File(dir,name));
        return false;
      else
        Matcher matcher = pattern.matcher(dir.getName()); // shouldnt that be 'name' instead of 'dir'?
        System.out.println("Accept: "+dir.getName()+"? "+matcher.matches());
        return matcher.matches();               
    }

  • A doubt on REG EXP

    Hi friends,
    Please clarify the following doubt in Reg Exp.
    Table EMP has following EMP_NAMEs:
    ============
    Anand
    Bala_G
    Chitra
    David_C
    Elango
    Fathima
    ============
    We have a set of characters as "abcdefghijklmnopqrstuvwxyz0123456789".
    Now we need to find the count of EMP_NAMES whose characters (any) are not in the list of characters in the above list. In this example, the result should be 2. i.e., 'Bala_D' and 'David_C'. The query should be like:
    Declare
    v_string varchar2(50) := 'abcdefghijklmnopqrstuvwxyz0123456789';
    v_count number(6);
    Begin
    select count(*)
    into v_count
    from emp
    where regexp_like(emp_name, v_string);
    dbms_output.put_line(v_count);
    end;
    ========================
    Thanks in advance!

    Hi,
    Welcome to the forum!
    To use REGEXP_LIKE, you could say:
    WHERE     REGEXP_LIKE ( emp_name
                  , '[^abcdefghijklmnopqrstuvwxyz0123456789]'
                  )However, it will be faster not to use regular expressions:
    WHERE   LTRIM ( emp_name
               , 'abcdefghijklmnopqrstuvwxyz0123456789'
               )          IS NOT NULLEdited by: Frank Kulash on Oct 10, 2012 4:18 PM
    Removed extra single-quote, after DAMorgan, below.

  • How to make Matcher stop once a reg exp match is found

    Is there a way to make the regular expression Matcher stop reading from the underlying CharSequence once it finds a match? For example, if I have a very long String and a match for some regular expression is at the beginning of the String, can I make the Matcher object stop examining the String once it finds the match? The Matcher object seems to always examine the entire CharSequence, even if a match is very near the beginning.
    Thanks,
    Zach Cox
    [email protected]

    Nope, {1}+ doesn't work either. I know it's
    continuing because I created my own CharSequence
    implementation that just wraps a String orwhatever,
    and I print to System.out whenever Matcher callsthe
    charAt method.What about the lookingAt() method?I think lookingAt is like matches, except just the beginning of the CharSequence has to match (i.e. starting at index 0), not the entire thing. I tried it and it doesn't even find the reg exp. The find method at least finds the reg exp, it just reads too far.

  • Reg Exp - not as expected

    Not often I ask questions myself, and perhaps my mind's just gone fuzzy this morning, but I'm having trouble doing a simple replace with regular expressions...
    In the below example I just want to replace all occurences of "fred" with "freddies"...
    SQL> ed
    Wrote file afiedt.buf
      1* select regexp_replace('this freddies is fred fred record', 'fred', 'freddies') from dual
    SQL> /
    REGEXP_REPLACE('THISFREDDIESISFREDFREDRECORD'
    this freddiesdies is freddies freddies recordbut, obviously, I don't want the existing "freddies" to become "freddiesdies", it should stay as it is. So if I check for spaces either side of the search string (and take account of it maybe being at the start/end of the string...
    SQL> ed
    Wrote file afiedt.buf
      1* select regexp_replace('this freddies is fred fred record', '(^| )fred( |$)', '\1freddies\2') from dual
    SQL> /
    REGEXP_REPLACE('THISFREDDIESISFREDFRE
    this freddies is freddies fred record
    SQL>It no longer replaces the "freddies" incorrectly, BUT it only replaces the first occurence of "fred" with "freddies" and not the latter one. ?!?!?!
    If I put an extra space inbetween the two "fred"s then it works:
    SQL> ed
    Wrote file afiedt.buf
      1* select regexp_replace('this freddies is fred  fred record', '(^| )fred( |$)', '\1freddies\2',2) from dual
    SQL> /
    REGEXP_REPLACE('THISFREDDIESISFREDFREDRECO
    this freddies is freddies  freddies record
    SQL>But I'm not going to have double spaces between the words and I can't determine where to insert them to make it work like this so it's not a feasible solution, although it does seem to highlight that the regular expression parser is not taking the space after the first match in the context of being the space before the second match.
    Is that a bug in the regular expression parser, a feature of the way regular expressions work (i.e. expected) or am I doing something wrong with my search and replace reg.exp. strings?
    Cheers

    I think this will explain ..
    SQL> select regexp_replace
      2         ('this freddies is fred fred  fred record',
      3          '(^| )(fred)($| )','\1freddies\3') str
      4  from dual
      5  /
    STR
    this freddies is freddies fred  freddies record
    1 row selected.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Reg Exp always returning false value

    Hi,
    Below is my code. I want to restrict the values to only alphabets and numbers and not special char.
    But the below condition fails on a positive value also. Ex: ABCD, abcd, 1234. These should be acceptable.
    Is the reg exp wrong?
    private var special_char:RegExp = /^[A-Za-z0-9]*$/;
                                  private function validateSpecialChar(inputValue:String):Boolean {
                                            if (special_char.test(inputValue))
                                                      valid = true;
                                            else
                                                      valid = false;
                                            return valid;
    Thanks,
    Imran

    Try: http://stackoverflow.com/questions/9012387/regex-expression-only-numbers-and-characters

  • Reg Exp confusion when searching for a '(' char

    Hello,
    I am trying to extract the name from the following HTML.
    onclick="searchCitationAuthor('Inoue, K.', true);">I want to be able to extract 'Inoue, K.'.
    My regular expression is as follows.
    "\\=true\\)\">([^<]+)</a>";I need to extract from the entire line of code. I need to extract from the =true chars as this makes the Reg Exp distinctive.
    I think the ')' char is confusing things.
    Can anyone suggest anything?
    Message was edited by:
    VanJay011379
    Sorry, I realize i was missing a ';' char. I thought the "\\)" was causing problems. Move on, nothing to see here LOL : )

    why not
    String regex = "searchCitatationAuthor\\s*\\(\\s*'([^']*)'"
    where is =true coming in though?

  • Explanation of my reg exp code

    Hi,
    When I run my code below, the line:
    Seat 4: playafly299 ($10 in chips)
    results in a match, but
    Seat 6: WillRyker ($5.55 in chips)
    results in a miss. Can someone explain why? I read the pattern below as:
    String literal Seat followed by one or more digits followed by colon followed by space followed by anything followed by space followed by character literal '(' followed by character literal '$' or nothing, followed by one or more digits followed by character literal '.' and one or more digits, OR nothing followed by string literal in chips. Am I missing something? Please help.
             String patternStr = "Seat (\\d+): (.+) \\(\\$?(\\d+[\\.\\d+]?) in chips\\)";
             Pattern p = Pattern.compile(patternStr);
             Matcher m = p.matcher(currentLine);         
             if ( m.find() ) {
                  System.out.println("MATCH:" +currentLine);
                  Table t = h.getTable();
                  int seat_num = Integer.parseInt(m.group(1));
                  String player_name = m.group(2);
                  double chip_stack = Double.parseDouble(m.group(3));
                  System.out.println("CREATING PLAYER: " +player_name+ " with stack: " +chip_stack);
                  Player player = new Player(player_name, chip_stack);
                  t.setPlayerAtSeat(seat_num, player);      
             } else {
                  System.out.println("MISS: " +currentLine);
             }

    Konigs wrote:
    Thank you Sabre. When are the other brackets appropriate?The square brackets are used to define a set of characters (not a sequence) and the () brackets define a group. You have an optional group that includes the decimal point so you need () not [] .

  • Reg exp trouble??

    Hi All,
    can someone tell me what is wrong with this code. I keep getting an Illegal State Exception, indicating it hasn't made a match, but I can't find anything wrong with the syntax. Yes, java.util.regex.*, is included at the start of the class.
        private void testReg()
            Pattern myPattern = Pattern.compile("dog");
            System.out.println(myPattern.pattern());
            Matcher myMatch = myPattern.matcher("dogdoggydogilicious");
            System.out.println(myMatch.start());
        }Any help would be appreciated. Thanks.

    LeWalrus wrote:
    Hi All,
    can someone tell me what is wrong with this code. I keep getting an Illegal State Exception, indicating it hasn't made a match, but I can't find anything wrong with the syntax. Yes, java.util.regex.*, is included at the start of the class.
    private void testReg()
    Pattern myPattern = Pattern.compile("dog");
    System.out.println(myPattern.pattern());
    Matcher myMatch = myPattern.matcher("dogdoggydogilicious");
    System.out.println(myMatch.start());
    }Any help would be appreciated. Thanks.Hi, you have to invoke e.g. myPattern.matches(); before you can use start!
    start
    public int start()
        Returns the start index of the previous match.
        Specified by:
            start in interface MatchResult
        Returns:
            The index of the first character matched
        Throws:
            IllegalStateException - If no match has yet been attempted, or if the previous match operation failedSo you should use one of these methods before invoking start.
          The matches method attempts to match the entire input sequence against the pattern.
          The lookingAt method attempts to match the input sequence, starting at the beginning, against the pattern.
          The find method scans the input sequence looking for the next subsequence that matches the pattern.See the API for more informations.
    http://java.sun.com/javase/6/docs/api/java/util/regex/package-summary.html
    http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html
    http://java.sun.com/javase/6/docs/api/java/util/regex/Matcher.html
    Greetings Michael
    Edited by: Urmech on Aug 13, 2008 7:04 AM

  • Reg Exp and non capturing groups

    Hello,
    I got problems with the non capturing groups in java.
    I want to extract the 2nd ocurenc of a given patern from a string.
    This ist the string =" 12.12.2004 [Logging] [Success] ### More text [Perhaps more brackets here] some text"
    Now I want to extract the 2nd occurecy of the brackets with an unknow text pattern.
    I tried this pattern = "(?:\[\w+\] )\[w+\]"
    I thought that the non-capturing pattern helps me to find the first pair of [] brackets. the capturing group should give me want i want.
    But I still get the result: [Logging] [Success]"
    Even if I try just to use only the non cpaturing patern "(?:\[\w+\])" I still get an output from Matcher.group() which I didnt expect here!
    What I am doing wrong?
    Thanx for any help

    Sorry, sabre150 I just missed it to answer you.
    I have placed it into eclipse in a scrapbookpage into the following code:
    final String regexp = "[^\\]]*\\[[^\\]]*\\]\\s*(.*)";
    final String zeile = " 12.12.2004 [Logging] [Success] ### More text [Perhaps more brackets here] some text";
    java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regexp);
    java.util.regex.Matcher matcher = pattern.matcher("");
    matcher.reset(zeile);
    System.out.println("Found: "+matcher.find());
    System.out.println(matcher.group());Output was:
    Found: true
    12.12.2004 [Logging] [Success] ### More text [Perhaps more brackets here] some text
    and not what I wanted
    "[Success] ### More text [Perhaps ...."
    I dont know what I am doing wrong.
    I thought I could solve it with the non-capturing group, but they doesnt seem to work.
    My question to the non-capturing group is:
    I have this pattern [code]"(?:.*)".
    This pattern will probably match the String "Hello Mary!"
    But it should not capture the string.
    So matcher.find() is true, but matcher.group() is the whole string and nit null, like I expected.

  • Reg exp help

    Hi
    I want to extract the first token of filename (and not the directory path) from a string like this:
    D:\MIRACLE\UPLOADS\1361\HG-ORA02#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
    /HG-ORA02#xaldb#alertlog_contents#22022010111941.mirdf.loadfailed_240210095258_62
    the tokens would bed HG-ORA02 in all instances
    Could you help me creating a reg expression to get the token?
    best regards
    Mette

    Hi,
    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; so is:
    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 that data.
    Assuming that
    (a) the filename is divided, first, by '/' or '\' characters, and
    (b) each of those parts may be divided into tokens by '.' or '#' characters, and that
    (c) we want the first (b) part of the last (a) part:
    SELECT     REGEXP_SUBSTR ( REGEXP_SUBSTR ( filename
                              , '[^/\]*$'
                    , '[^.#]+'
                    ) AS token_1
    FROM     table_x;Here, the inner REGEXP_SUBSTR finds the last part delimited by / or \. You can add other delimiters by putting them in the square brakets, anywhere after ^.
    The outer REGEXP_SUBSTR operates on the results of the inner one. It returns the first part delimited by . or #. Again, you can add other delimiters.

  • Reg Exp help needed (trouble with line breaks)

    Hello,
    I am attempting to parse a line of text with regular expressions. I am having difficulty with the line breaks.
    I want to divide the following line by the first '\n' char.
    For instance, I wan the output to be as follows:
    found 1: one
    found 2: ddd
    dddHowever, I get the following with my attached code:
    found 1: one
    found 2: dddHowever, the second line break seems to be the end of the second group.
    How do I get the any character '.' to read past any subsequent line breaks?
    import java.util.regex.*;
    public class Test
         String rawSequenceArg = ">one\nddd\nddd";     
           Pattern p = Pattern.compile(">([^\n]+)\n(.+)");
           Matcher m = p.matcher(rawSequenceArg);
           if(m.find())
                System.out.println("found 1: " + m.group(1));
                System.out.println("found 2: " + m.group(2));
    }

    In this case, the DOTALL flag is the one you need; it allows the dot (period, full stop) to match line separator characters. MULTILINE makes the '^' and '$' anchors match the beginning and end of logical lines, instead of just the beginning and end of the input.

  • Reg exp in form

    Hello,
    I need some help on reg expressions.
    I want to allow users to type a url on my html page. The way I currently handle this situations is this:
    myString = myString.replaceAll("(?:https?|ftp)://\\S+(?<![,.?!)])", "<a href=\"$0\">$0</a>");
    so when the user types in a url such as http://www.java.sun it would display it back as a url that he/she can click on. This part works fine
    However, if the user types in something like this:
    <img src="http://www.someUrl.com/img.gif"/> it fails. In this case the user should see the image but he/she does not.
    How can I make sure that only those instances get replaced where only URL is typed which is not part of other html. Should I add blank spaces before and after the url?
    Thank you.

    Will there be any links in the source document that are already in the processed format? That is, http://www.somewhere.org/If so, you'll need to match the whole element so don't accidentally match a URL within it. Then you can deal with the situation you brought up, where a start tag has a URL attribute. For that, just match any complete start tag and plug it back in. That should take care of any URL's that are contained within larger structures, leaving only "naked" URL's that need to be processed.
    A simple replaceAll() won't work here, because you're doing different things with the text depending on what was matched. The Matcher class provides lower-level operations that let you do that kind of thing, but Elliott Hughes has written a nice little utility called Rewriter that does most of the work for you. Here's how you might use it:     String regex = "(?is)"  // CASE-INSENSITIVE and DOTALL modes
                    + "<a\\s[^>]++>.*?</a>"  // a complete A element
                    + "|"                    // or
                    + "<[a-z]+\\s[^>]++>"    // a start tag with attributes
                    + "|"                    // or
                    + "(?:https?|ftp)://\\S+(?<![,.?!)])";  // a URL
        Rewriter rewriter = new Rewriter(regex)
          public String replacement()
            String found = group(0);
            return found.startsWith("<") ? found :
                "<a href=\"" + found + "\">" + found + "</a>";
        String resultStr = rewriter.rewrite(args[0]);

  • Strange behavior when searching a phrase using reg exp and dynamic sql

    Hi,
    I have a strange issue while using dynamic sql for an apex page. I have a requirement to search a string in the database column which is entered by user on a page item. The search process should search the whole phrase only.
    I have a query generated dynamically in the back end and use it in a cursor in the stored procedure
      SELECT t.group_cn , t.group_desc, t.group_type, t.partner_organization_id, t.partner_organization
      FROM vr_idm_group t WHERE regexp_like(t.group_desc,'(^|\W)HR Selection & Assignment(\W|$)', 'i')The pl sql code with the dynamic sql statements are below.
       IF p_search_process NOT in ('PARTNER') THEN
          OPEN v_cursor FOR v_sql;
       ELSE
          OPEN v_cursor FOR v_sql USING p_search_id;
       END IF;
       LOOP
          FETCH v_cursor INTo v_obj.group_cn, v_obj.group_desc, v_obj.group_type, v_obj.partner_organization_id,
             v_obj.partner_organization, v_obj.match_count;
          EXIT WHEN v_cursor%NOTFOUND ;
          v_search_array.extend;
          v_search_array(v_search_array.last) := v_obj;
          dbms_output.put_line(v_sql);
       END LOOP;The search works fine if the search string does not contain any special character like &,- etc.
    However, if the search string contains any special character, it does not return any thing. This strange issue happens only if I call the procedure from the apex page and the search string contains a special character. (please note that the procedure works fine even from apex if the string does not have a special character). When I debugged this, found that, the cursor does not fetch any rows (it is supposed to fetch two rows) for unknown reason. When I run the query separately, it returns the two rows (in which the column group_desc contains the search string "HR Selection & Assignment") as desired. Also, when I test the procedure in the back end (PLSQL developer), it works fine.
    Any idea, what is causing this strange behaviour?
    Advance thanks.
    Regards,
    Natarajan

    i don't see anything about a dataProvider.  you're assigning a source for a scrollpane.  scrollpane's don't have a dataProvider property.
    anyway, other than arrayRun always being false when that last if-statement executes, what's the problem?  doesn't that movieclip display when that 2nd branch of the last if-statement executes (assuming instance is defined correctly etc)?

  • Using reg exp's in filters

    We have followed the recommendation to convert the cache database from Derby to MSSQL.
    There seems to be an un-documented disadvantage in this:
    regular expressions are no longer supported in filters !
    Can anyone confirm this ?
    We are running TES 6.1.0 with MSSQL 2008 database.

    you can try a combination of instr() and substr() function. the example below is using an instr() function to determine the position of the last comma that is used in the string. the substr() function takes cares of the getting the last word that is used in the string with the help of the instr() function.
    SQL> select substr(a.str,instr(a.str,',',-1)+1) last_string
      2    from (select 'abcd,def,hijk,lmno,pqrs' str from dual) a ;
    LAST_STRING
    pqrs
    SQL>

Maybe you are looking for

  • Special characters in iWeb sites

    Hello I understand that it is not advisable to use special characters in the name of an iWeb website, but what about when inserting text into the site? For example would it be ok to write é as in café as part of the heading in a Home page ?

  • Dcount function in power query

    Hi, I have a query generated in power query that gives me the following results: ID          VALUES              1              A001 2              A002 3              A001 4              B001 5              B002 6              B001 I need to insert

  • Research Resources and Rules of Engagement

    Hi experts and wanna-be experts: Welcome to the Utilities space on SCN. Before anything else, read The SCN Rules of Engagement Update 09/09/2012 - search enhancements are available in SCN: Custom Google Search for SCN content http://bit.ly/new-scn-se

  • Games don't work, why wasn't it obvious

    I purchased a game on iTunes, and then found out my iPod Mini won't play it. There was no warning to me during my purchase, which really stinks. Now what?

  • Headaches with Leopard

    Hello. Im having various problems with 10.5.1. I find the Finder to be very buggy. For starters, it is very slow when navigating through and opening Finder. I have never worked with such a slow "explorer". And I come from 98SE and Pentium II. My prev