StringMatcher
See original GitHub issueWe have a CharMatcher
but its capabilities are limited. I would like to have the ability to match more complex strings. Examples:
- Strings starting with three letters and ending with a digit (e.g.
"var3"
,"abc8"
):StringMatcher.inRange('a', 'z').times(3).then(StringMatcher.digit())
- Strings containing words with semicolons (e.g.
"cat;dog;bird;"
):StringMatcher.inRange('a', 'z').oneOrMore().then(StringMatcher.char(';')).oneOrMore()
- Strings representing integer numbers (e.g.
"17"
,"-1"
):StringMatcher.anyOf("-+").optional().then(StringMatcher.digit().oneOrMore())
- Strings containing either words or
123
(e.g. “bird
”,"dDd"
,"123"
):StringMatcher.inRange('a', 'z').or(StringMatcher.inRange('A','Z')).oneOrMore() .or(StringMatcher.str("123"))
Yes, these all can be done via regular expressions. But I hate regular expressions since they are not readable and not checked at compile time.
Do we need such feature in Guava?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:16 (4 by maintainers)
Top Results From Across the Web
StringMatcher (Apache Commons Text 1.10.0 API)
Returns the number of matching characters, zero for no match. This method is called to check for a match. The parameter pos represents...
Read more >ExampleMatcher.StringMatcher (Spring Data Core 3.0.0 API)
Returns an array containing the constants of this enum class, in the order they are declared. Methods inherited from class java.lang.
Read more >StringMatcher Class Reference - LLVM
Given a list of strings and code to execute when they match, output a simple switch tree to classify the input string.
Read more >String matcher (proto) - Envoy Proxy
Specifies a list of ways to match a string. { "patterns": [] } Copy to clipboard. patterns. (repeated type.matcher.v3.StringMatcher, REQUIRED).
Read more >StringMatcher (Quartz Parent POM 2.1.7 API)
public abstract class StringMatcher<T extends Key<?>> ... An abstract base class for some types of matchers. Author: jhouse; See Also: Serialized Form ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@orionll, you seem to imply that people advocating for “just” using regular expressions don’t “care about the type safety and the quality of their software”. That’s kind of a blanket statement (or even a covert insult).
Note that the type safety provided by the proposed alternative would guard against syntax errors, but not necessarily semantic errors. The question is then: which category of error is the user of regular expressions more likely to make. The latter, I claim, because a dev will run the code they write at least once, thus uncovering syntax errors before they’re ever committed.
As for software quality: regular expressions are well understood and should be part of every developer’s toolkit. To invent an alternative could thus also be considered a case of NIH.
Thanks @jbduncan. I’m happy to know that there people who care about the type safety and the quality of their software.