commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <>
Subject [jira] [Commented] (LANG-1046) containsPattern method for StringUtils?
Date Thu, 12 Mar 2015 16:34:40 GMT


Sebb commented on LANG-1046:

The first two can currently be written as:

assertTrue(Pattern.compile("alpha.*").matcher("alphabet").matches()); // or "alphabet".matches("alpha.*");

The 3rd would need to done by updating the RE as follows:


The only string matching that is directly supported by the String class is String.matches()
which matches the whole string.
Of course that can be used for the other cases by prefixing/appending ".*" as necessary to
the RE, but that's a bit messy.

Perhaps there is a use-case for adding a method to do startsWith matching as well.
For consistency, perhaps one should support all 3 match types?
i.e. match all, match start, match part.

> containsPattern method for StringUtils?
> ---------------------------------------
>                 Key: LANG-1046
>                 URL:
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Sebb
>             Fix For: Discussion
> The JVM Matcher class only supports anchored matches.
> It might perhaps be useful to add a containsPattern(CharSequence input, String pattern)
method that returns true if the input contains the pattern.

This message was sent by Atlassian JIRA

View raw message