Results 1 to 6 of 6
Thread: [SOLVED] help with RegExp
- 05-22-2008, 04:03 AM #1
[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 :
Well it always shows "Not matched". I'm lost, please reply.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"); } } }
- 05-22-2008, 04:16 AM #2
oh nevermind i found out i was using "matches" instead of "find" method. thanks anyway.
- 05-22-2008, 04:25 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Remove white spaces there.
Java Code:Pattern.compile("<.*>");
- 05-22-2008, 04:26 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Read the JavaDoc, the way you used here is not safer at all in some cases.
- 05-23-2008, 12:36 AM #5
I have another problem with regularEXP please go to[SOLVED] More RegEx help
- 05-23-2008, 04:05 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If you solve this please mark thread solved. It's really helpful to all of members here. Is that my help really valid for you? :)


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks