Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

group capturing help

Last post 12-01-2008, 9:30 AM by kminev. 20 replies.
Page 2 of 2 (21 items)   < Previous 1 2
Sort Posts: Previous Next
  •  11-24-2008, 1:18 PM 48776 in reply to 48772

    Re: group capturing help

    You just aren't printing all the groups.

    In your loop your test condition is less than the total number of groups.Should be less than or equal to

    kminev:

    This is my implementation code: (The input is the same as the one I posted previously)

    private void cmeParser(String filePath) throws FileNotFoundException, IOException {

            FileInputStream fis = null;
            BufferedInputStream bis = null;
            DataInputStream dis = null;
            String lineTemp = "";
            Matcher m;

            try {
                fis = new FileInputStream(filePath);
                bis = new BufferedInputStream(fis);
                dis = new DataInputStream(bis);
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("Input Stream failed to open");
            }

            String regEx = "(?=.+?OrderStatus\\(Routed=)((?:\\d\\d\\.){2}\\d{4})\\s+((?:\\d\\d:){2}\\d\\d\\.\\d+).+?OrderStatus\\(Routed=\\S+\\x20[A-Z]\\x20[A-Z]\\x20[A-Z]\\x20([A-Z\\x20]+)\\x20\\d+\\x20(CME-[A-Z]|CBOT-[A-Z])\\s\\S+\\s(\\w{2}\\x20\\d+).+?(TTORD\\S+).+?((?:\\d{1,3}\\.){3}\\d{1,3})\\x20exchange_order_id\\x20(\\w+).+?Latency=(\\d+)";

            Pattern p = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);

            lineTemp = dis.readLine();
            m = p.matcher(lineTemp);

            while (dis.available() != 0) {


                if (m.find()) {

                    System.out.println("Found something");
                    //DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG
                    StringBuilder displayResult = new StringBuilder();
                    for (int x = 1; x < m.groupCount(); x++) {
                        displayResult.append(" (" + m.group(x) + ") ");
                    }
                    System.out.println("Before Parsed: " + lineTemp);
                    System.out.println("RESULT: " + displayResult);
                } else {
                    System.out.println("Found nothing");
                }

                lineTemp = dis.readLine();
                m = p.matcher(lineTemp);
            }

        }

     

    Kind of bizarre why I am missing latency value.

     

    Thank you.


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  11-26-2008, 12:01 PM 48845 in reply to 48770

    Re: group capturing help

    I am still not able to extract the value from the Latency parameter.

    Sorry for being annoying, but just ran out of options with my limitted regex skill set.

    Input is very Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;} appreciated.

  •  11-26-2008, 1:36 PM 48851 in reply to 48845

    Re: group capturing help

    kminev:

    I am still not able to extract the value from the Latency parameter.

    Sorry for being annoying, but just ran out of options with my limitted regex skill set.

    Input is very Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;} appreciated.

    At this point I don't think it is a regex issue anymore, but an implementation of Java problem.  The value was obviously matched in the example I provided since it was required for the match to work at all.  You could try to run the previously supplied code sample against your input and see what you get.

    You should consult someone with Java experience who can look at your code with you to see in they can see any logic errors.


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  11-26-2008, 2:40 PM 48852 in reply to 48851

    Re: group capturing help

    I don't think that it fails, because of java syntax. In my group[0] I can see that the latency is captrued, but then I can't  extract this value from my groups.

     I am pasting my java implementation as well as the output:

         public static final void main(String[] args) throws IOException {

            //String filePath = "c:\\Logs\\serverttmd_TestFiles\\FMT_FMTORDEQ1TCME03_CME-C_2008-11-17__SLO_.log";
            String filePath = "c:\\Logs\\serverttmd_TestFiles\\FMT_FMTORDEQ1TCBT03_CBOT_2008-11-10__SLO_.log";
            String filePathNetstat = "c:\\Logs\\netstat\\FMT_192.168.1.100_2008-11-21_NS_.txt";
            //ServerttmdParser.SloLog(filePath);

            String sourcestring = "17.11.2008 00:00:03.513 | ORDERSERVER/PROD | 3988 | INFO | 00000000 | JVV714 | OrderStatus(Routed=(sts:8202 C S O Autotrader    4 CME-C FUT 6B 0309     0.0   14751 0 L   X:   0 W:   4    A15085450 TTORDERERCN1EMICHAEL A1     GTD    06:00:03.000 No. 14144932 sndr 67.202.68.182 exchange_order_id 0008F6AS sok: 09093C957) Latency=16) some junk";
            Pattern re = Pattern.compile("(?=.+?OrderStatus\\(Routed=)((?:\\d\\d\\.){2}\\d{4})\\s+((?:\\d\\d:){2}\\d\\d\\.\\d+).+?OrderStatus\\(Routed=\\S+\\x20[A-Z]\\x20[A-Z]\\x20[A-Z]\\x20([A-Z\\x20]+)\\x20\\d+\\x20(CME-[A-Z])\\s\\S+\\s(\\w{2}\\x20\\d+).+?(TTORD\\S+).+?((?:\\d{1,3}\\.){3}\\d{1,3})\\x20exchange_order_id\\x20(\\w+).+?Latency=(\\d+)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
            Matcher m = re.matcher(sourcestring);
            int mIdx = 0;
            
            while (m.find()) {
                for (int groupIdx = 0; groupIdx < m.groupCount(); groupIdx++) {
                    System.out.println("[" + mIdx + "][" + groupIdx + "] = " + m.group(groupIdx));
                }
                mIdx++;
            }
           


        }

     

    Output:

     

    init:
    deps-jar:
    Compiling 1 source file to C:\Development\Java\RegExTest\build\classes
    compile:
    run:
    [0][0] = 17.11.2008 00:00:03.513 | ORDERSERVER/PROD | 3988 | INFO | 00000000 | JVV714 | OrderStatus(Routed=(sts:8202 C S O Autotrader    4 CME-C FUT 6B 0309     0.0   14751 0 L   X:   0 W:   4    A15085450 TTORDERERCN1EMICHAEL A1     GTD    06:00:03.000 No. 14144932 sndr 67.202.68.182 exchange_order_id 0008F6AS sok: 09093C957) Latency=16
    [0][1] = 17.11.2008
    [0][2] = 00:00:03.513
    [0][3] = Autotrader  
    [0][4] = CME-C
    [0][5] = 6B 0309
    [0]Devil = TTORDERERCN1EMICHAEL
    [0][7] = 67.202.68.182
    [0]Music = 0008F6AS
    BUILD SUCCESSFUL (total time: 0 seconds)
     

     I am almost at a point where I would start parsing it the old fashioned way line by line with split.

     

    Thank in advance for looking into this for me.

     

  •  11-26-2008, 3:12 PM 48854 in reply to 48852

    Re: group capturing help

    Seems that the Java group loop code was missing a +1 in the group count.  I have fixed the code generation at myregextester.com.

    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    class Module1{
      public static void main(String[] asd){
      String sourcestring = "17.11.2008 00:00:03.513 | ORDERSERVER/PROD | 3988 | INFO | 00000000 | JVV714 | OrderStatus(Routed=(sts:8202 C S O Autotrader    4 CME-C FUT 6B 0309     0.0   14751 0 L   X:   0 W:   4    A15085450 TTORDERERCN1EMICHAEL A1     GTD    06:00:03.000 No. 14144932 sndr 67.202.68.182 exchange_order_id 0008F6AS sok: 09093C957) Latency=16) some junk";
      Pattern re = Pattern.compile("(?=.+?OrderStatus\\(Routed=)((?:\\d\\d\\.){2}\\d{4})\\s+((?:\\d\\d:){2}\\d\\d\\.\\d+).+?OrderStatus\\(Routed=\\S+\\x20[A-Z]\\x20[A-Z]\\x20[A-Z]\\x20([A-Z\\x20]+)\\x20\\d+\\x20(CME-[A-Z])\\s\\S+\\s(\\w{2}\\x20\\d+).+?(TTORD\\S+).+?((?:\\d{1,3}\\.){3}\\d{1,3})\\x20exchange_order_id\\x20(\\w+).+?Latency=(\\d+)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
      Matcher m = re.matcher(sourcestring);
      int mIdx = 0;
        while (m.find()){
          for( int groupIdx = 0; groupIdx < m.groupCount()+1; groupIdx++ ){
            System.out.println( "[" + mIdx + "][" + groupIdx + "] = " + m.group(groupIdx));
          }
          mIdx++;
        }
      }
    }


  •  12-01-2008, 9:30 AM 49025 in reply to 48854

    Re: group capturing help

    Thanks everyone. I decided to step away from RegEx for now and first read a book on it so I can get more familiar with the syntax.

     

    I will stick with the old fashioned method of parsing text files for now.

     

    Thanks

Page 2 of 2 (21 items)   < Previous 1 2
View as RSS news feed in XML