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 [] .

Similar Messages

  • 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 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();               
    }

  • 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?

  • 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?

  • 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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • HT2240 I purchased a QT Pro Reg. Code Key. When I install it in the QT Preferences Panel, I get an: "Invalid Registration" note at the bottom, next to the "Buy QuickTime Pro" button to the right. Both on a desk top and a laptop. Win 7, QT version 7.7.1. N

    I purchased a QT Pro Reg. Code Key. When I install it in the QT Preferences Panel, I get an: "Invalid Registration" note at the bottom, next to the "Buy QuickTime Pro" button to the right. Both on a desk top and a laptop. Win 7, QT version 7.7.1. No joy! I've been on the phone with Apple for a little more than an hour, so far. They have my money. anyone have any Ideas? Just kiss the thirty bucks goodbye?

    You,Sir, are "The Man"! I followed the instructions and - viola - Joy in Mudville. Thank you, keep up the great work. Even the "Apple" people don't seem to know this. I was on the phone with them, passed from one to another, for over an hour. While waiting I stumbled on your advise and I was made free! If they ask you, charge them a mint for the information. You Sir have gone where no Apple has gone before.

  • Reg process code FM

    HI friends,
    We use same process code in outbound and inbound? If different process code means how to do? If different process code means function codes are differs or same ...please give me  clear explanation
    regards
    Mani

    Hi Mani,
    Outbound and inbound process codes are different and the function modules are also different for each process code.
    For outbound, the process code is defined in the messagecontrol (in WE20 partner profile definition).
    For inbound the process code is defined in the inbound options.(in WE20).
    Every process code will have to be linked to message type and function module in WE64.
    In WE57 also you need to define the link between logical message type and the FM.
    Hope this helps.

  • 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)?

  • Reg:T-CODE for open and close period for materials(new plant).

    hi sap guru's
    T-code for following process
        can anybody send me , how to create calendar to new plant . and what is the T-code to be use for open and close period of materials for new plant.
    thanks
    sakthi..

    Hi Sakthi,
    I am assuming that you are asking about the factory calendars which are assigned while difing the plant.
    Factory calendars are created through transaction "SCAL".
    Opening and closing of MM periods can be done through transaction MMPV.This is based on the company code.Before using MMPV ,you can look the last opened period in the transaction MMRV.
    Reward points if it helps.
    Regards
    Karan

  • Reg:package code to refresh materialized views

    i am new to pl/sql packages and procedures.i want it to execute for running mappings in informatica which takes 0 and gives 1 when executed successfully
    create or replace PACKAGE BODY pkg_refresh_mv as
    procedure prc_mv (p_mv_name varchar2) is
    begin
    dbms_mview.refresh (p_mv_name);
    end prc_mv;
    procedure refresh_all_mv (proc_response IN OUT number) is
    begin
    dbms_mview.refresh('materialized view','C');
    dbms_mview.refresh('materialized view','C');
    proc_response := 1;
    exception
    when others then
    proc_response := 0;
    end refresh_all_mv ;
    end pkg_refresh_mv;
    when i execute this code i get the following errors
    PLS-00201: identifier 'PKG_REFRESH_MV' must be declared
    PLS-00304: cannot compile body of 'PKG_REFRESH_MV' without its specification
    what needs to be changed
    thanks

    try this one :
    CREATE OR REPLACE PACKAGE pkg_refresh_mv
    AS
       PROCEDURE prc_mv (p_mv_name VARCHAR2);  
       PROCEDURE refresh_all_mv (proc_response IN OUT NUMBER);
    END pkg_refresh_mv;
    CREATE OR REPLACE PACKAGE BODY pkg_refresh_mv
    AS
       PROCEDURE prc_mv (p_mv_name VARCHAR2)
       IS
       BEGIN
          dbms_mview.refresh (p_mv_name);
       END prc_mv;
       PROCEDURE refresh_all_mv (proc_response IN OUT NUMBER)
       IS
       BEGIN
          dbms_mview.refresh ('materialized view', 'C');
          dbms_mview.refresh ('materialized view', 'C');
          proc_response := 1;
       EXCEPTION
          WHEN OTHERS
          THEN
             proc_response := 0;
       END refresh_all_mv;
    END pkg_refresh_mv;
    /

  • Reg: ABAP code for customer exit variable

    Hi Team,
    I have a requirement to create a report  based on an multiprovider 'TEST'.
    Based on the input selection of Period; I need to define a Keyfigure X which will be a count of value available for that Period in one cube involved in the MProvider. E.g.: If for period 12, the value = 1 in the cube; then this keyfigure will give the count as 1 in the output of the report.
    The second KF Y values are available in the second infocube directly: ibut should be displayed based on the value of the KF 'X' with logic as if X > 0 ; then the values should be read from the second infocube in the report. & if X <= 0; no values should be displayed.
    Please help me with the ABAP code to be used in the query level.
    Thanks & Regards
    Sneha

    Hi Sneha,
       I would suggest the following
    1.Please change the design the cube and include a key figure Zcount that would be incremented for each record.
    Now as per the first requirement you need to get the count for a Input Period from First cube
    This would be very simple to implement , all you have to do is restrict this KF with the Input characteristic/variable and also the First Infocube.
    2.You can also use exception aggreation counter to address this requirement . Even in this case you need to include a dummy key figure in the cube and the exception characteristic would be the period in the Infocube.
    But performance would be on downside when compared to the first one.
    3.The second requirement is quite simple
    Create a formula KF as follows
      (KF1 > 0)*KF2 . 
      KF1 > 0 is a logical operation and it would always return 1 on success and 0 otherwise.
    Hope this helps,
    Regards,
    James Harold.

  • Reg Tax Codes and Plants

    Hi Gurus,
    1) I am creating a PO. It doesnt have a Material as it is a text req converted to PO. I am having 10 plants which uses various Tax codes which will auto populate according to the plants. Now my requirement is i want to populate a tax code (XX) for 8 plants i am using and (YY) for 9th Plant and (ZZ) for 10th Plant.
    I dont have a material number. But i am having a Vendor Number, a Plant. We are not creating the PO's manually. This will be done by a Batchjob, so manually entering is also not possible.
    2) Also i want to overwrite the Tax code which is populating automatically with the Tax code from PIR. Please advice where we will be maintaining the Config for Tax Code and Plant/Company code.
    Please advice on this issue and how to proceed further.Thanks for your help in advance.
    Thanks,
    Sakkithyan

    Hi,
    If you want to default the tax code in the purchase order then create info record using transaction ME11..
    If you want to default tax code in MIRO then do it using transaction OMR2..
    Regards,
    Chintan Joshi

Maybe you are looking for

  • Key mapping not working in FB4

    In Windows/Preferences/General/Keys..  I've built the following key mapping.  I want to be able to press F9 key on my keyboard, and, whether I'm in Source editor view, or MXML design view, I want to start the compile and run process.  But I can't get

  • Blue Screen of Death with v.8 upgrade.  Please help!!!

    I tried upgrading to itunes v.8, but got blue screen of death. I've tried several times, with the same result. I tried suggestion on here...I went to itunes.exe and changed compatability to XP, but when I click it, it says there is a problem that nee

  • How do you suggest I best import and edit many portions of old VHS?

    I read the recent postings on digitizing the multiple DVD's and found that to be quite interesting and enlightening. I have searched through the archives but didn't run into a posting with exactly my question and I apologize because I know there are

  • Applescript to open a file in mplayer

    Hello, I've been trying to write an applescript that simply opens a file and the passes the path of that file to mplayer with "do shell script." I can figure out how to make it work by using a select file dialog, but I can't seem to make it work as a

  • IPhone photo stream photos import to macbook Pro but photos in albums on the same phone do not?

    iPhone photo stream photos import to macbook Pro but photos in albums on the same phone do not? When I connected my iPhone to the MB-Pro and imported the photos, all the ones on the phone in "the photo stream" came in fine, But I have 4 "albums" cont