K
kaeli
Okay, so I want this to return only the first match, like <a
href='someUrl.html'>some link</a>, but it returns the whole match. How
to I match the *shortest* occurance?
TIA
import java.io.*;
import java.util.*;
import java.util.regex.*;
public class testPatternMatching extends Object
{
public static void main(String [] args)
{
String pageContent = "<a href='someUrl.html'>some link</a> more
text blah <a href='anotherUrl.html'>another link</a> more text blah";
String s = null;
try
{
Pattern p = Pattern.compile("<a.*href=.*>.*?</a>",
Pattern.DOTALL);
Matcher m = p.matcher(pageContent);
s = m.find()?m.group():"";
System.out.println(s);
}
catch (Exception e)
{
System.out.println("Exception occured:");
System.out.println(e.getMessage());
}
}
};
--
href='someUrl.html'>some link</a>, but it returns the whole match. How
to I match the *shortest* occurance?
TIA
import java.io.*;
import java.util.*;
import java.util.regex.*;
public class testPatternMatching extends Object
{
public static void main(String [] args)
{
String pageContent = "<a href='someUrl.html'>some link</a> more
text blah <a href='anotherUrl.html'>another link</a> more text blah";
String s = null;
try
{
Pattern p = Pattern.compile("<a.*href=.*>.*?</a>",
Pattern.DOTALL);
Matcher m = p.matcher(pageContent);
s = m.find()?m.group():"";
System.out.println(s);
}
catch (Exception e)
{
System.out.println("Exception occured:");
System.out.println(e.getMessage());
}
}
};
--