在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:VerbalExpressions/JavaVerbalExpressions开源软件地址:https://github.com/VerbalExpressions/JavaVerbalExpressions开源编程语言:Java 99.5%开源软件介绍:JavaVerbalExpressionsVerbalExpressions is a Java library that helps to construct difficult regular expressions. Getting StartedMaven Dependency: <dependency>
<groupId>ru.lanwen.verbalregex</groupId>
<artifactId>java-verbal-expressions</artifactId>
<version>1.8</version>
</dependency> You can use SNAPSHOT dependency with adding to <repositories>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories> ExamplesVerbalExpression 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); //True
testRegex.toString(); // Outputs the regex used:
// ^(?:http)(?:s)?(?:\:\/\/)(?:www\.)?(?:[^\ ]*)$ 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: VerbalExpression regex = regex(regex().anything().addModifier('i')).endOfLine().build(); Or can be used in another regex: 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: regex().wordChar().nonWordChar()
.space().nonSpace()
.digit().nonDigit() Define captures: 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 examplesOther implementationsYou can view all implementations on VerbalExpressions.github.io [ Javascript - PHP - Python - C# - Objective-C - Ruby - Groovy - Haskell - C++ - ... (moarr) ] Project released with travisWith help of this tutorial: https://dracoblue.net/dev/uploading-snapshots-and-releases-to-maven-central-with-travis/ |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论