@Test public void shouldReturnTrueIfMatchesUsingAsterisk() { String input = "aaa"; String regularExpression = "a*"; boolean result = simpleRegularExpression.evaluate(input, regularExpression); assertTrue(result); }
public boolean evaluate(String source, String pattern) { if (source == null || pattern == null) { throw new IllegalArgumentException("You can't pass a null strings as input"); } if (pattern.length() == 0) return source.length() == 0; if (pattern.length() == 1 || pattern.charAt(1) != '*') { if (source.length() < 1 || (pattern.charAt(0) != '.' && source.charAt(0) != pattern.charAt( 0))) { return false; } return evaluate(source.substring(1), pattern.substring(1)); } else { int len = source.length(); int i = -1; while (i < len && (i < 0 || pattern.charAt(0) == '.' || pattern.charAt(0) == source.charAt( i))) { if (evaluate(source.substring(i + 1), pattern.substring(2))) return true; i++; } return false; } }
SimpleRegularExpression { public boolean evaluate(String source, String pattern) { if (source == null || pattern == null) { throw new IllegalArgumentException("You can't pass a null strings as input"); } if (pattern.length() == 0) return source.length() == 0; if (pattern.length() == 1 || pattern.charAt(1) != '*') { if (source.length() < 1 || (pattern.charAt(0) != '.' && source.charAt(0) != pattern.charAt( 0))) { return false; } return evaluate(source.substring(1), pattern.substring(1)); } else { int len = source.length(); int i = -1; while (i < len && (i < 0 || pattern.charAt(0) == '.' || pattern.charAt(0) == source.charAt( i))) { if (evaluate(source.substring(i + 1), pattern.substring(2))) return true; i++; } return false; } } }
SimpleRegularExpression { public boolean evaluate(String source, String pattern) { if (source == null || pattern == null) { throw new IllegalArgumentException("You can't pass a null strings as input"); } if (pattern.length() == 0) return source.length() == 0; if (pattern.length() == 1 || pattern.charAt(1) != '*') { if (source.length() < 1 || (pattern.charAt(0) != '.' && source.charAt(0) != pattern.charAt( 0))) { return false; } return evaluate(source.substring(1), pattern.substring(1)); } else { int len = source.length(); int i = -1; while (i < len && (i < 0 || pattern.charAt(0) == '.' || pattern.charAt(0) == source.charAt( i))) { if (evaluate(source.substring(i + 1), pattern.substring(2))) return true; i++; } return false; } }  }
SimpleRegularExpression { public boolean evaluate(String source, String pattern) { if (source == null || pattern == null) { throw new IllegalArgumentException("You can't pass a null strings as input"); } if (pattern.length() == 0) return source.length() == 0; if (pattern.length() == 1 || pattern.charAt(1) != '*') { if (source.length() < 1 || (pattern.charAt(0) != '.' && source.charAt(0) != pattern.charAt( 0))) { return false; } return evaluate(source.substring(1), pattern.substring(1)); } else { int len = source.length(); int i = -1; while (i < len && (i < 0 || pattern.charAt(0) == '.' || pattern.charAt(0) == source.charAt( i))) { if (evaluate(source.substring(i + 1), pattern.substring(2))) return true; i++; } return false; } }  boolean evaluate(String source, String pattern); }
SimpleRegularExpression { public boolean evaluate(String source, String pattern) { if (source == null || pattern == null) { throw new IllegalArgumentException("You can't pass a null strings as input"); } if (pattern.length() == 0) return source.length() == 0; if (pattern.length() == 1 || pattern.charAt(1) != '*') { if (source.length() < 1 || (pattern.charAt(0) != '.' && source.charAt(0) != pattern.charAt( 0))) { return false; } return evaluate(source.substring(1), pattern.substring(1)); } else { int len = source.length(); int i = -1; while (i < len && (i < 0 || pattern.charAt(0) == '.' || pattern.charAt(0) == source.charAt( i))) { if (evaluate(source.substring(i + 1), pattern.substring(2))) return true; i++; } return false; } }  boolean evaluate(String source, String pattern);  }