commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (LANG-1046) containsPattern method for StringUtils?
Date Thu, 12 Mar 2015 16:35:38 GMT

    [ https://issues.apache.org/jira/browse/LANG-1046?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14358926#comment-14358926
] 

Sebb edited comment on LANG-1046 at 3/12/15 4:34 PM:
-----------------------------------------------------

The first two can currently be written as:

{code:java}
assertTrue(Pattern.compile("alpha.*").matcher("alphabet").matches()); // or "alphabet".matches("alpha.*");
assertTrue(Pattern.compile("alpha.").matcher("alphabet").lookingAt());
{code}

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

{code:java}
assertTrue(Pattern.compile(".*"+"ph.b").matcher("alphabet").lookingAt());
{code}

The only string matching that is directly supported by the String class is String.matches(RE)
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.


was (Author: sebb@apache.org):
The first two can currently be written as:

{code:java}
assertTrue(Pattern.compile("alpha.*").matcher("alphabet").matches()); // or "alphabet".matches("alpha.*");
assertTrue(Pattern.compile("alpha.").matcher("alphabet").lookingAt());
{code}

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

{code:java}
assertTrue(Pattern.compile(".*"+"ph.b").matcher("alphabet").lookingAt());
{code}

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: https://issues.apache.org/jira/browse/LANG-1046
>             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
(v6.3.4#6332)

Mime
View raw message