code_junkie

RegEx Whitespace Vs. Eclipse

Nov 13th, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. Powered[s]*[bB]y.*MyBB
  2.  
  3. "Powered[\s]*[bB]y.*MyBB"
  4.  
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7.  
  8. import org.junit.Assert;
  9. import org.junit.Test;
  10.  
  11.  
  12. public class RegexTest {
  13. @Test
  14. public void testPatternWithWhiteSpace(){
  15. Pattern pattern = Pattern.compile("Powered\s*[bB]y.*MyBB");
  16. Matcher matcher = pattern.matcher("Powered By MyBB");
  17. Assert.assertTrue(matcher.matches());
  18. matcher = pattern.matcher("Powered_By MyBB");
  19. Assert.assertFalse(matcher.matches());
  20. }
  21. }
  22.  
  23. matcher = pattern.matcher("Poweredtnr By MyBB");
  24. Assert.assertTrue(matcher.matches());
  25. matcher = pattern.matcher("Poweredtnr ,By MyBB");
  26. Assert.assertFalse(matcher.matches());
Add Comment
Please, Sign In to add comment