Results 1 to 5 of 5
  1. #1
    somer81 is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default trouble in getting pattern with regex

    hello, I have two dimensional array dataX and it stores kinds of information as below

    name = Redondo Peak
    photo = Redondo peak-composite2.jpg
    photo_caption =
    elevation_ft = 11258
    elevation_ref = {{NAVD88}}<ref name="ngs">
    {{cite ngs
    id = FO1482
    .
    .
    .

    and it goes like that for 40 peaks..

    I want to get "name = ......." patterns to be able to handle each peak's name.

    my code is like

    REGEX = "(name)\\s+\\=\\s+[a-zA-Z0-9]+" ;

    dataX = new String[temp.length][];

    Pattern p = Pattern.compile(REGEX);
    Matcher m ;

    for ( String line : temp )
    {
    dataX[count++] = line.split("\\|\\s"); \\ puts data into array as I showed above
    }

    // I expect from the loop below to store name=...... values into data4 array string but does not work
    for(int i=0,t=0; i<dataX.length; i++)
    {
    for(int j=0; j<dataX[i].length; j++)
    {
    m = p.matcher(dataX[i][j]);

    while(m.find()) {

    data4[t] = m.group() ;
    t++;
    }
    }
    }

    for(int x =0; x <data4.length ; x++)
    System.out.println(data4[x]); // throws nullpointer exception


    any idea please ?

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: trouble in getting pattern with regex

    Who creates the source of the data? is it you or someone else?

  3. #3
    somer81 is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default Re: trouble in getting pattern with regex

    i solved it thanks friend
    the data actualy come from wiki dump xml file.
    but I get the data from xml and split it. After splitting
    I stored them into dataX two dimensional array.

    thnks

  4. #4
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: trouble in getting pattern with regex

    Why didn't you just parse the XML to get the values directly?

    There are tools in java to read XML files for you.

    You could have read the values into objects and then write/map those objects to a database.

    Read it: (don't ignore it)
    A simple way to read an XML file in Java - Java sample code - developer Fusion

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,248
    Rep Power
    19

    Default Re: trouble in getting pattern with regex

    somer81, don't you think it's bad manners to ignore a response on an earlier thread and go ahead and post a new question? Surely ozzyman deserves to know whether his advice was appreciated.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. regex.pattern need help understanding
    By fishy8158 in forum New To Java
    Replies: 3
    Last Post: 11-23-2011, 02:05 AM
  2. Need help with regex pattern
    By b_jones10634 in forum Advanced Java
    Replies: 1
    Last Post: 09-24-2010, 08:02 PM
  3. Regex for the pattern
    By mallikarjun_sg in forum Advanced Java
    Replies: 12
    Last Post: 05-06-2010, 12:16 PM
  4. Regex Pattern/Matcher - Print only one occurrence!
    By racha0601 in forum Advanced Java
    Replies: 3
    Last Post: 04-06-2009, 05:05 PM
  5. Regex pattern
    By ravian in forum New To Java
    Replies: 4
    Last Post: 12-11-2007, 10:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •