Results 1 to 6 of 6
  1. #1
    JT4NK3D's Avatar
    JT4NK3D is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default [SOLVED] help with RegExp

    Im trying to use regular expressions to identify xhtml tags in a file and then show how many in total and how many of each unique tag there is in the file.
    This is just a test to make sure it recognizes < and > as a tag but it doesnt seem to be working :
    Java Code:
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    public class RegularExpExp {
    
        public static void main(String[] args) {
    
            String inputStr = " <p> ";     // a random tag to see if it works
            Pattern pattern = Pattern.compile("< .* >"); // that should mean "<" anything at all ">"
            Matcher matcher = pattern.matcher(inputStr);
    
            if (matcher.matches()) {
                System.out.println("Matched");
            } else {
                System.out.println("Not Matched");
            }
        }
    }
    Well it always shows "Not matched". I'm lost, please reply.

  2. #2
    JT4NK3D's Avatar
    JT4NK3D is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Talking

    oh nevermind i found out i was using "matches" instead of "find" method. thanks anyway.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    JT4NK3D's Avatar
    JT4NK3D is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Default

    I have another problem with regularEXP please go to[SOLVED] More RegEx help

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •