question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

We 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:open
  • Created 7 years ago
  • Reactions:1
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
Stephan202commented, Dec 30, 2016

@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.

3reactions
orionllcommented, Dec 30, 2016

Thanks @jbduncan. I’m happy to know that there people who care about the type safety and the quality of their software.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found