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

    Default Regular expressions

    i have an assignment that i have to read the links in this web page https://www.cs.drexel.edu/~kschmidt/...va/sample.html

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

    Java Code:
    import java.io.*;
    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='mailto:kschmidt+cs265@cs.drexel.edu'>");
        inputs.add("<a href=https://software.drexel.edu>here</a>");
        Pattern p = Pattern.compile(expr2);
        for (String s : inputs) {
          System.out.println("s= " + s);
          Matcher m = p.matcher(s);
          System.out.println(m.group(0));
          System.out.println(m.group(1));
        }
      }
    }
    this assignment is due in two hours! gunna fail this class!

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: Regular expressions

    What doesn't it match that you think it should?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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
  •