T
Tom Maki
Hi,
I have to admit I have never been good at regular expressions and I
have a piece of code that I want to write using the java.util.regex
package. It is quite simple -- it is for a compression filter. Once
thing that is a bit different is that I want to compress all web pages
that don't have the subsequence 'admin' in them (these pages all go
over a LAN so compression would be counterproductive. I can't just
invert the find () boolean since the client will be changing the reg.
exp. over time. Anyway, here is the test case I have been using. You
notice is fails on assertFalse(pattern.matcher(adminUri).find())
statement:
import java.util.regex.Pattern;
import junit.framework.TestCase;
public class RegularExpressionTest extends TestCase {
public void testRexEx() {
String adminUri = "/rss/admin_product_types_start.do";
String reportUri = "/rss/price_change_report_start.do";
String regEx = "[^a][^d][^m][^i][^n]";
Pattern pattern = Pattern.compile(regEx);
assertTrue(pattern.matcher(reportUri).find());
assertFalse(pattern.matcher(adminUri).find());
}
}
Any help would be greatly appreciated!
Thanks,
Tom Maki
I have to admit I have never been good at regular expressions and I
have a piece of code that I want to write using the java.util.regex
package. It is quite simple -- it is for a compression filter. Once
thing that is a bit different is that I want to compress all web pages
that don't have the subsequence 'admin' in them (these pages all go
over a LAN so compression would be counterproductive. I can't just
invert the find () boolean since the client will be changing the reg.
exp. over time. Anyway, here is the test case I have been using. You
notice is fails on assertFalse(pattern.matcher(adminUri).find())
statement:
import java.util.regex.Pattern;
import junit.framework.TestCase;
public class RegularExpressionTest extends TestCase {
public void testRexEx() {
String adminUri = "/rss/admin_product_types_start.do";
String reportUri = "/rss/price_change_report_start.do";
String regEx = "[^a][^d][^m][^i][^n]";
Pattern pattern = Pattern.compile(regEx);
assertTrue(pattern.matcher(reportUri).find());
assertFalse(pattern.matcher(adminUri).find());
}
}
Any help would be greatly appreciated!
Thanks,
Tom Maki