Skip to content

Commit 549d58e

Browse files
committed
fix - up dep version in readme
and extend examples section
1 parent 8991930 commit 549d58e

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

README.md

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Maven Dependency:
1515
<dependency>
1616
<groupId>ru.lanwen.verbalregex</groupId>
1717
<artifactId>java-verbal-expressions</artifactId>
18-
<version>1.1</version>
18+
<version>1.2</version>
1919
</dependency>
2020
```
2121

@@ -32,14 +32,11 @@ You can use *SNAPSHOT* dependency with adding to `pom.xml`:
3232
##Examples
3333
```java
3434
VerbalExpression testRegex = VerbalExpression.regex()
35-
.startOfLine()
36-
.then("http")
37-
.maybe("s")
38-
.then("://")
39-
.maybe("www.")
40-
.anythingButNot(" ")
41-
.endOfLine()
42-
.build();
35+
.startOfLine().then("http").maybe("s")
36+
.then("://")
37+
.maybe("www.").anythingButNot(" ")
38+
.endOfLine()
39+
.build();
4340

4441
// Create an example URL
4542
String url = "https://www.google.com";
@@ -48,13 +45,14 @@ String url = "https://www.google.com";
4845
testRegex.testExact(url); //True
4946

5047
testRegex.toString(); // Outputs the regex used:
51-
// ^(?:http)(?:s)?(?:\:\/\/)(?:www\.)?(?:[^\ ]*)$
48+
// ^(?:http)(?:s)?(?:\:\/\/)(?:www\.)?(?:[^\ ]*)$
5249

50+
```
51+
52+
```java
5353
VerbalExpression testRegex = VerbalExpression.regex()
54-
.startOfLine()
55-
.then("abc")
56-
.or("def")
57-
.build();
54+
.startOfLine().then("abc").or("def")
55+
.build();
5856

5957
String testString = "defzzz";
6058

@@ -66,10 +64,36 @@ testRegex.getText(testString); // returns: def
6664

6765
Builder can be cloned:
6866
```java
69-
// Produce: (.*)$
7067
VerbalExpression regex = regex(regex().anything().addModifier('i')).endOfLine().build();
68+
```
69+
70+
Or can be used in another regex:
71+
```java
72+
VerbalExpression.Builder digits = regex().capt().digit().oneOrMore().endCapt().tab();
73+
VerbalExpression regex2 = regex().add(digits).add(digits).build();
74+
```
75+
76+
Feel free to use any predefined char groups:
77+
```java
78+
regex().wordChar().nonWordChar()
79+
.space().nonSpace()
80+
.digit().nonDigit()
7181
```
7282

83+
Define captures:
84+
```java
85+
String text = "aaabcd";
86+
VerbalExpression regex = regex()
87+
.find("a")
88+
.capture().find("b").anything().endCapture().then("cd").build();
89+
90+
regex.getText(text) // returns "abcd"
91+
regex.getText(text, 1) // returns "b"
92+
```
93+
94+
## More complex examples
95+
* [Parse long strings example](/VerbalExpressions/JavaVerbalExpressions/wiki/Parse-long-strings-example)
96+
7397
## Other implementations
7498
You can view all implementations on [VerbalExpressions.github.io](http://VerbalExpressions.github.io)
7599

0 commit comments

Comments
 (0)