Results 1 to 2 of 2
  1. #1
    freelancer is offline Member
    Join Date
    Nov 2011
    Rep Power

    Default Regular expressions

    i have an assignment that i have to read the links in this web page

    but i cant figure out the regular expression that matches all "or any" of them here is my code

    Java Code:
    import java.util.*;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class regextest
      public static void main( String[] args )
        String expr = "<a[^>]+href=[\"']?([^'\"> ]+)[\"']?[^>]*>";
        String expr2 = " *(?i)href *= *(\"([^\"]*\")|\'[^\"]*\'|([^'"";
        ArrayList<String> inputs = new ArrayList<String>();
        inputs.add("<a href='../../../index.html'>relative link</a>");
        inputs.add("<a href=''>");
        inputs.add("<a href=>here</a>");
        Pattern p = Pattern.compile(expr2);
        for (String s : inputs) {
          System.out.println("s= " + s);
          Matcher m = p.matcher(s);
    this assignment is due in two hours! gunna fail this class!

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Washington, DC
    Rep Power

    Default Re: Regular expressions

    What doesn't it match that you think it should?
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

Similar Threads

  1. Regular Expressions Help
    By Death Sickle in forum New To Java
    Replies: 4
    Last Post: 04-04-2011, 04:21 AM
  2. Regular Expressions for certain format
    By mohammedelbes in forum Advanced Java
    Replies: 3
    Last Post: 01-06-2011, 06:00 PM
  3. Regular Expressions problem
    By mohammedelbes in forum Advanced Java
    Replies: 7
    Last Post: 01-05-2011, 11:12 AM
  4. regular expressions
    By sozeee in forum New To Java
    Replies: 3
    Last Post: 12-06-2010, 09:58 PM
  5. Regular Expressions in java
    By blue404 in forum Advanced Java
    Replies: 2
    Last Post: 09-26-2008, 03:43 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