Skip to content

Commit

Permalink
Replaced builder pattern approach with method cascades approach. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ne4istb committed Jan 19, 2016
1 parent e11aefd commit 9433f43
Show file tree
Hide file tree
Showing 37 changed files with 644 additions and 489 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## 0.0.1
## 0.2.0
- breaking change: builder pattern approach replaced with method cascades. [More details](https://github.com/VerbalExpressions/DartVerbalExpressions/issues/6)
- set global search by default

## 0.1.0

- Initial version, created by Ne4istb
30 changes: 15 additions & 15 deletions README.md
Expand Up @@ -13,11 +13,11 @@ Dart package info is here: https://pub.dartlang.org/packages/verbal_expressions

```dart
var regex = new VerbalExpression()
.startOfLine()
.then("http").maybe("s")
.then("://")
.maybe("www.").anythingBut(" ")
.endOfLine();
..startOfLine()
..then("http").maybe("s")
..then("://")
..maybe("www.").anythingBut(" ")
..endOfLine();
// Create an example URL
String url = "https://www.google.com";
Expand All @@ -30,8 +30,7 @@ Dart package info is here: https://pub.dartlang.org/packages/verbal_expressions
```

```dart
var regex = new VerbalExpression()
.startOfLine().then("abc").or("def");
var regex = new VerbalExpression()..startOfLine()..then("abc")..or("def");
var testString = "defzzz";
//Use VerbalExpression's hasMatch() method to test if parts if the string match the regex
Expand All @@ -41,18 +40,19 @@ Dart package info is here: https://pub.dartlang.org/packages/verbal_expressions
Feel free to use any predefined char groups:
```dart
var regex = new VerbalExpression()
.wordChar().nonWordChar()
.space().nonSpace()
.digit().nonDigit();
..wordChar()..nonWordChar()
..space()..nonSpace()
..digit()..nonDigit();
```

Define captures:
```dart
RegExp regex = new VerbalExpression()
.find("a")
.beginCapture().find("b").anything().endCapture()
.then("cd")
.toRegExp();
var expression = new VerbalExpression()
..find("a")
..beginCapture()..find("b")..anything()..endCapture()
..then("cd");
RegExp regex = expression.toRegExp();
var match = regex.firstMatch(text);
print(match.group(0)); // returns "abcd"
Expand Down
81 changes: 39 additions & 42 deletions example/verbal_expressions_example.dart
Expand Up @@ -24,61 +24,58 @@ main() {
domain = getDomain('http://ru.wikipedia.org/wiki/Dart');
print(domain); // .org

var testString = new VerbalExpression()
.find('dog')
.stopAtFirst()
.withAnyCase()
.replace('Replace first DoG in the sentence but do not touch second dog',
'cat');

print(
testString); // Replace first cat in the sentence but do not touch second dog
var expression = new VerbalExpression()
..find('dog')
..stopAtFirst()
..withAnyCase();

var testString = expression.replace('Replace first DoG in the sentence but do not touch second dog', 'cat');

print(testString); // Replace first cat in the sentence but do not touch second dog
}

String getDomain(String url) {
var regex = new VerbalExpression()
.startOfLine()
.then("http")
.maybe("s")
.then("://")
.maybe("www.")
.anythingBut(" ")
.beginCapture()
.then('.')
.anythingBut('/')
.endCapture()
.anything()
.endOfLine()
.toRegExp();

return regex.firstMatch(url).group(4);
var expression = new VerbalExpression()
..startOfLine()
..then("http")
..maybe("s")
..then("://")
..maybe("www.")
..anythingBut(" ")
..beginCapture()
..then('.')
..anythingBut('/')
..endCapture()
..anything()
..endOfLine();

return expression.toRegExp().firstMatch(url).group(4);
}

bool matchTelephoneNumber(String number) {
var regex = new VerbalExpression()
.startOfLine()
.then("+")
.beginCapture()
.range([new Range('0', '9')])
.count(3)
.maybe("-")
.maybe(" ")
.endCapture()
.count(3)
.endOfLine();
..startOfLine()
..then("+")
..beginCapture()
..range([new Range('0', '9')])
..count(3)
..maybe("-")..maybe(" ")
..endCapture()
..count(3)
..endOfLine();

return regex.hasMatch(number);
}

bool matchUrl(String url) {
var regex = new VerbalExpression()
.startOfLine()
.then("http")
.maybe("s")
.then("://")
.maybe("www.")
.anythingBut(" ")
.endOfLine();
..startOfLine()
..then("http")
..maybe("s")
..then("://")
..maybe("www.")
..anythingBut(" ")
..endOfLine();

return regex.hasMatch(url);
}

0 comments on commit 9433f43

Please sign in to comment.