Other Reg Expr in Java

Discussion in 'Software' started by ZthDimension, 25 Oct 2009.

  1. ZthDimension

    ZthDimension Zth

    Joined:
    21 May 2009
    Posts:
    38
    Likes Received:
    2
    Basically I'm not particualry sure what I'm doing in life in Reg Expr(So please excuse the mess), just a quick bit of code as a example

    Code:
    private String NameCountryData;
    private String [] Country;
    private String [] surname;
    private String [] name;
    
    NameCountryData = "England (2006)/Blogg, Fred/Davey, Jen/Doe, Jane"
    
    title = NameCountryData.split("\\(\\d\\d\\d\\d\\)/"); //Splitting the data in half from 
    England(whilst removing (2006) so have two array positions one with "England" in and the 
    other containing the rest) 
    
    surname = title[1].split(); //these are the two lines I'm struggling with, not sure what Reg 
    Expr I need to split this on the ", " after Blogg and for the reg expr only to match ", " 
    ONCE so I end up with only two array postions similar to above.
    name = surname[1].split();// Same as above
    
    
    I hope I've explained what I'm trying to do above reasonably clearly but the end result I want to end up with I'm trying to get to look like this:

    title[0] = England
    title[1] = Blogg, Fred/Davey, Jen/Doe, Jane
    surname[0] = Blogg
    surname[1] = Fred/Davey, Jen/Doe, Jane
    name[0] = Fred
    name[1] = Davey, Jen/Doe, Jane

    I assume its possible but I've spent the past two hours banging my head over this, I know its quite simple but can't work it out!

    Cheers if you can help

    Marc

    PS This is sample code, so most probably won't/shouldn't compile
     
    Last edited: 26 Oct 2009

Share This Page