Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/VerbalExpressions/JavaVerbalExpressions
Java regular expressions made easy.
https://github.com/VerbalExpressions/JavaVerbalExpressions
Last synced: 11 days ago
JSON representation
Java regular expressions made easy.
- Host: GitHub
- URL: https://github.com/VerbalExpressions/JavaVerbalExpressions
- Owner: VerbalExpressions
- License: mit
- Created: 2013-07-25T16:15:26.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2024-10-02T00:08:56.000Z (about 1 month ago)
- Last Synced: 2024-10-16T14:05:10.751Z (23 days ago)
- Language: Java
- Homepage:
- Size: 177 KB
- Stars: 2,620
- Watchers: 101
- Forks: 242
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - VerbalExpressions/JavaVerbalExpressions - Java regular expressions made easy. (Java)
README
JavaVerbalExpressions
=====================
[![release](http://github-release-version.herokuapp.com/github/VerbalExpressions/JavaVerbalExpressions/release.svg?style=flat)](https://github.com/VerbalExpressions/JavaVerbalExpressions/releases/latest) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/ru.lanwen.verbalregex/java-verbal-expressions/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/ru.lanwen.verbalregex/java-verbal-expressions)
[](https://github.com/VerbalExpressions/JSVerbalExpressions)
[![Coverage Status](https://coveralls.io/repos/VerbalExpressions/JavaVerbalExpressions/badge.svg)](https://coveralls.io/r/VerbalExpressions/JavaVerbalExpressions)VerbalExpressions is a Java library that helps to construct difficult regular expressions.
## Getting Started
Maven Dependency:
```xml
ru.lanwen.verbalregex
java-verbal-expressions
1.8```
You can use *SNAPSHOT* dependency with adding to `pom.xml`:
```xml
ossrh
https://oss.sonatype.org/content/repositories/snapshots
```
## Examples
```java
VerbalExpression testRegex = VerbalExpression.regex()
.startOfLine().then("http").maybe("s")
.then("://")
.maybe("www.").anythingBut(" ")
.endOfLine()
.build();// Create an example URL
String url = "https://www.google.com";// Use VerbalExpression's testExact() method to test if the entire string matches the regex
testRegex.testExact(url); //TruetestRegex.toString(); // Outputs the regex used:
// ^(?:http)(?:s)?(?:\:\/\/)(?:www\.)?(?:[^\ ]*)$```
```java
VerbalExpression testRegex = VerbalExpression.regex()
.startOfLine().then("abc").or("def")
.build();String testString = "defzzz";
//Use VerbalExpression's test() method to test if parts if the string match the regex
testRegex.test(testString); // true
testRegex.testExact(testString); // false
testRegex.getText(testString); // returns: def
```Builder can be cloned:
```java
VerbalExpression regex = regex(regex().anything().addModifier('i')).endOfLine().build();
```Or can be used in another regex:
```java
VerbalExpression.Builder digits = regex().capt().digit().oneOrMore().endCapt().tab();
VerbalExpression regex2 = regex().add(digits).add(digits).build();
```Feel free to use any predefined char groups:
```java
regex().wordChar().nonWordChar()
.space().nonSpace()
.digit().nonDigit()
```Define captures:
```java
String text = "aaabcd";
VerbalExpression regex = regex()
.find("a")
.capture().find("b").anything().endCapture().then("cd").build();regex.getText(text) // returns "abcd"
regex.getText(text, 1) // returns "b"
```## More complex examples
* [Parse long strings example](https://github.com/VerbalExpressions/JavaVerbalExpressions/wiki/Parse-long-strings-example)## Other implementations
You can view all implementations on [VerbalExpressions.github.io](http://VerbalExpressions.github.io)[
[Javascript](https://github.com/VerbalExpressions/JSVerbalExpressions) -
[PHP](https://github.com/VerbalExpressions/PHPVerbalExpressions) -
[Python](https://github.com/VerbalExpressions/PythonVerbalExpressions) -
[C#](https://github.com/VerbalExpressions/CSharpVerbalExpressions) -
[Objective-C](https://github.com/VerbalExpressions/ObjectiveCVerbalExpressions) -
[Ruby](https://github.com/ryan-endacott/verbal_expressions) -
[Groovy](https://github.com/VerbalExpressions/GroovyVerbalExpressions) -
[Haskell](https://github.com/VerbalExpressions/HaskellVerbalExpressions) -
[C++](https://github.com/VerbalExpressions/CppVerbalExpressions) - ... ([moarr](https://github.com/VerbalExpressions)) ]## Project released with travis
With help of this tutorial:
https://dracoblue.net/dev/uploading-snapshots-and-releases-to-maven-central-with-travis/