Regex

I'm using the regex pattern and matcher classes, but i don't know how to look for what i want.Pattern pattern = Pattern.compile(\\something\\);

i need to know what to put in the something to give me everything between <td style='width:140;padding:0in;height:7.5pt'> the "<>" any suggestions would help

[324 byte] By [mark07a] at [2007-11-27 10:23:17]
# 1

Actualy i should be more specific... i am trying to put everything that's in the "<>" into 1 string and anything not in them in another the data sorta looks like this\ </font>July 022007 6:30 </span></strong>

</td>

mark07a at 2007-7-28 17:21:03 > top of Java-index,Java Essentials,Java Programming...
# 2

Examples and tutorials on using regex: ^_^

http://www.regular-expressions.info/java.html

http://java.sun.com/developer/technicalArticles/releases/1.4regex/

http://www.exampledepot.com/egs/java.util.regex/pkg.html

http://www.developer.com/java/other/article.php/1460561

http://www.go4expert.com/forums/showthread.php?t=1074

Yannixa at 2007-7-28 17:21:03 > top of Java-index,Java Essentials,Java Programming...
# 3

@mark07

are you nolonger happy with the charAt method ? ;o)

do you remember what I said to you yesterday ?!!

look at this code and try to improve the pattern:

private static final String REGEX = ">(\\s*?)(\\w+)(\\s*?)(\\d{2})(\\s*?),(\\s*?)(\\d{4})(\\s*?)<";

public static void Test() {

Pattern p = Pattern.compile(REGEX);

Matcher matcher;

matcher = p.matcher("<span> July 12, 2007 </span>");

if (matcher.find()) {

System.out.println("pattern found:");

System.out.println("start: "+matcher.start());

System.out.println("end:"+matcher.end());

}else{

System.out.println("pattern not found!!");

}

}

Hope That Helps

java_2006a at 2007-7-28 17:21:03 > top of Java-index,Java Essentials,Java Programming...
# 4

> @mark07

> are you nolonger happy with the charAt method ? ;o)

>

> do you remember what I said to you yesterday ?!!

>

Ya i do and used it to put each table row into an array like this

[code]\while (front <= stop)

{

front = text.indexOf("<tr>",front);

back = text.indexOf("</tr>", front + 1);

while (front < back)

{

row[index] += text.charAt(front);

front++;

}

index++;

}[\code]

but i figured using the regex class would be a whole lot easier for this next part and ya that helps a lot thanks!

mark07a at 2007-7-28 17:21:03 > top of Java-index,Java Essentials,Java Programming...
# 5

Like this?

String text = "</font>July 02 2007 6:30</span></strong>

</td>";

Pattern pattern = Pattern.compile("(?<=\\>)[^<]+");

Matcher matcher = pattern.matcher(text);

while(matcher.find()) {

System.out.println(matcher.group());

}

prometheuzza at 2007-7-28 17:21:03 > top of Java-index,Java Essentials,Java Programming...
# 6

sort of but how do i put the date inside a string without the other text im trying to get rid of?

mark07a at 2007-7-28 17:21:03 > top of Java-index,Java Essentials,Java Programming...
# 7

> look at this code and try to improve the pattern:

>

That wouldn't be hard... Improving it, that is. It is hard to try and understand it though!

> private static final String REGEX =

> =

> ">(\\s*?)(\\w+)(\\s*?)(\\d{2})(\\s*?),(\\s*?)(\\d{4})(

> \\s*?)<";

>

prometheuzza at 2007-7-28 17:21:03 > top of Java-index,Java Essentials,Java Programming...
# 8

> sort of but how do i put the date inside a string

> without the other text im trying to get rid of?

Well, I print the date somewhere. Have a wild guess how you'd go about assigning it to a String variable.

; )

prometheuzza at 2007-7-28 17:21:03 > top of Java-index,Java Essentials,Java Programming...
# 9

> Well, I print the date somewhere. Have a wild guess

> how you'd go about it and assigning it to a String

> variable.

> ; )

lol ok either i wasn't clear or i have no clue what to do i got this huge line of html code and in it is a date and a project name all i want is those 2 things and not any of the html code so im trying to parse out everything in the <> and just leave the next

mark07a at 2007-7-28 17:21:03 > top of Java-index,Java Essentials,Java Programming...
# 10

> ...

> lol ok either i wasn't clear or i have no clue what

> to do i got this huge line of html code and in it is

> a date and a project name all i want is those 2

> things and not any of the html code so im trying to

> parse out everything in the <> and just leave the next

String s = matcher.group();

prometheuzza at 2007-7-28 17:21:03 > top of Java-index,Java Essentials,Java Programming...
# 11

and the light bulb flickers on... =) Thanks!

mark07a at 2007-7-28 17:21:03 > top of Java-index,Java Essentials,Java Programming...