Results 1 to 6 of 6

Thread: Regex for defining headers

  1. #1
    Join Date
    Dec 2009
    Posts
    263

    Regex for defining headers

    Hello,
    I have a file that lists points in 3D cad that he has a point number followed by its coordinates XY Z. I come to the parsers, but it is possible that there have a header at the beginning that could contain numbers
    Code:
    This is the file
        1    1.2617199222332623    0.725695013999939    0.02221299916302136
        2    3.1561200956726071    -0.2960570096969601    0.06121500107019912
        3    3.1561200956726071    -0.9510160022539121    0.07097199217609727
        1    -1.2603299617767331    -1.7529099107196015    0.06372000277012329
        5    -3.156170022092225    -1.2122600251052232    0.051357999111007271
    So I use the pattern class and I have a concern with the item identifier which can be confused with numbers in the header. So I created a pattern that would result in a figure between spaces ( "" or "\ t") using the \ s but it did not work. Anyone have a solution for this? Thank you

  2. #2
    Join Date
    Nov 2009
    Posts
    330

    Re: Regex for defining headers

    Hello,
    I have a regular expression with me, if you need you can use it.
    Code:
    String str = "(-?\\d + (<a href = "file:/ / \ \. \ \ d "target =" _blank "> \ \. \ \ d </ a >+)?)";
    String lnpt = "^\\t (<a href = "file:/ / \ \ d "target =" _blank "> \ \ d </ a> +) \ \ t" + <blockquote> str + "<a href =" file: / / \ \ t "target =" _blank " > \ \ t </ a> "
    + + Decimal_pattern "<a href ="file:/ / \ \ t "target =" _blank "> \ \ t </ a>"
    + + Decimal_pattern "$";
    </ blockquote>

  3. #3
    Join Date
    Dec 2009
    Posts
    192

    Re: Regex for defining headers

    Hello,
    I am trying the same kind of a program. So, I tested the above regular expression. But it does not work for me.
    Code:
    Pattern1 Pat = Pattern.compiles("\\s (\\+ d)\\s ");
    It does not ID because you said at the beginning ^ \ \ t and there is a space or a tab on both sides of the ID. Even i am interested in this topic and if any one has a solution for this then please do post back, i am very much interested in it. Thanks in advance.

  4. #4
    Join Date
    Nov 2009
    Posts
    333

    Re: Regex for defining headers

    Hello,
    Try with AC
    Code:
    [ \ t]*([1-9]+)[ \ t]+([\\-1-9\\.]+)[ \ t]+([\\-1-9\\.]+)[ \ t]+([\\-1-9\\.]+)
    We can probably be shorter but it should work. I mean to say that if you need you can shorten the length of the regular expression, but i have not tried that, though you can give a try to that and if it works then do not forget to post it back so that eve i can use it.

  5. #5
    Join Date
    Dec 2009
    Posts
    263

    Re: Regex for defining headers

    Hello,
    The thing that I did to pattern. An identifier for a contact to the top because I had everything together but I had a problem of casting float to int.
    So I separated the address and it works
    Code:
    Pattern pat = Pattern.compiles("-?[0-9]+(\\. [0-9] + (E [+-][ 0-9] (2 })?)");
    This does not work,
    Code:
    [+ -] because there may be the exponential.
    By the way thanks for all the help.

  6. #6
    Join Date
    Nov 2009
    Posts
    347

    Re: Regex for defining headers

    Hello,
    i am new to this , but I have done some coding on it, please check if it works with you.
    Code:
    while ((line = buff.readLine()) != null)
                { 
                    fnd =false;
                    
                    tab_sm sm = new tab_sm();
                    
                    Pattern1 Pattern = Pattern.compiles("[\ t ]\\d + [\ t ]");
                    Matcher mt1 = pat1.mt(row);
                    if(mt1.find()){
                        
                        
                        number[0]= mt1.group();
                        System.out.System.out.println("tey"+ number[0]);
                        / / removes spaces and tabs
                        number[0] = Number[0].replaceAll(" ","");
                        number[0] = Number[0].replaceAll("\ t","");
                    }
                    
                    Pattern pat = Pattern.compiles("-?[0-9]+(\\. [0-9] + (E [+-][ 0-9] (2 })?)");
                    Matcher mt = pat.mt(row);
                    
                    
                    i =1;
                    while (mt.find()) {
                        number[i] = new String(mt.group());
                        i + +;
                        fnd =true;
                        / / Treatment
                    }
                    if(Find){
                        sm.setId(Integer.parseInt(number[0]));
                        sm.setX(Double.parseDouble(number[1]));
                        sm.setY(Double.parseDouble(number[2]));
                        sm.setz(Double.parseDouble(number[3]));
                        
                        tab_pts.add(sm);
                    }
                }

Similar Threads

  1. Defining and controlling database in SQL
    By GOOL in forum Software Development
    Replies: 5
    Last Post: 25-12-2010, 08:42 AM
  2. Defining a Remote Object in Java
    By Dharamsi in forum Software Development
    Replies: 5
    Last Post: 18-02-2010, 08:10 PM
  3. Defining primary key on database table
    By Garlands in forum Software Development
    Replies: 4
    Last Post: 09-02-2010, 09:09 PM
  4. Defining a Layout using SMIL and HTML
    By Anathakrishnan in forum Windows Software
    Replies: 3
    Last Post: 30-04-2009, 10:34 AM
  5. Defining Chapters in Movie Maker
    By Will in forum Vista Help
    Replies: 4
    Last Post: 27-07-2007, 01:14 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,140,852.55882 seconds with 17 queries