Results 1 to 5 of 5
- 03-23-2012, 03:25 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
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 ?
-
Re: trouble in getting pattern with regex
Who creates the source of the data? is it you or someone else?
- 03-23-2012, 06:07 AM #3
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
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
-
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
- 03-27-2012, 03:23 AM #5
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.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
Similar Threads
-
regex.pattern need help understanding
By fishy8158 in forum New To JavaReplies: 3Last Post: 11-23-2011, 03:05 AM -
Need help with regex pattern
By b_jones10634 in forum Advanced JavaReplies: 1Last Post: 09-24-2010, 09:02 PM -
Regex for the pattern
By mallikarjun_sg in forum Advanced JavaReplies: 12Last Post: 05-06-2010, 01:16 PM -
Regex Pattern/Matcher - Print only one occurrence!
By racha0601 in forum Advanced JavaReplies: 3Last Post: 04-06-2009, 06:05 PM -
Regex pattern
By ravian in forum New To JavaReplies: 4Last Post: 12-11-2007, 11:20 AM
Bookmarks