You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (JIRA)" <ji...@apache.org> on 2012/10/05 03:09:47 UTC

[jira] [Created] (LANG-841) Add StringUtils replaceAllPatternDotAll and removeAllPatternDotAll

Gary D. Gregory created LANG-841:
------------------------------------

             Summary: Add StringUtils replaceAllPatternDotAll and removeAllPatternDotAll
                 Key: LANG-841
                 URL: https://issues.apache.org/jira/browse/LANG-841
             Project: Commons Lang
          Issue Type: New Feature
          Components: lang.*
         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
Maven home: C:\Java\apache-maven-3.0.4\bin\..
Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_35\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
            Reporter: Gary D. Gregory
         Attachments: lang-841.diff

Patch attached. 

Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (LANG-841) Add StringUtils replaceAllPatternDotAll and removeAllPatternDotAll

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-841?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory updated LANG-841:
---------------------------------

    Attachment: lang-841.diff
    
> Add StringUtils replaceAllPatternDotAll and removeAllPatternDotAll
> ------------------------------------------------------------------
>
>                 Key: LANG-841
>                 URL: https://issues.apache.org/jira/browse/LANG-841
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>         Attachments: lang-841.diff
>
>
> Patch attached. 
> Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (LANG-841) Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-841?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory updated LANG-841:
---------------------------------

    Description: 
I often want to call:

{code:java}
"OldValue\nOldValue".replaceAll("Regex", "NewValue")
{code}

where the old value has end of line chars. So I need to do this:

{code:java}
Pattern.compile("Regex", Pattern.DOTALL).matcher("OldValue\nOldValue").replaceAll("NewValue");
{code}

which I put in a util methods, which feels like it could be in StringUtils:

{code:java}
    /**
     * Replaces each substring of the source String that matches the given regular expression with the given
     * replacement using the DOTALL option.
     * 
     * @param source
     *            the source string
     * @param regex
     *            the regular expression to which this string is to be matched
     * @param replacement
     *            the string to be substituted for each match
     * @return The resulting {@code String}
     * @see String#replaceAll(String, String)
     * @see Pattern#DOTALL
     * @since 3.2
     */
    public static String replaceAllPatternDotAll(String source, String regex, String replacement) {
        return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement);
    }

    /**
     * Removes each substring of the source String that matches the given regular expression using the DOTALL option.
     * 
     * @param source
     *            the source string
     * @param regex
     *            the regular expression to which this string is to be matched
     * @return The resulting {@code String}
     * @see String#replaceAll(String, String)
     * @see Pattern#DOTALL
     * @since 3.2
     */
    public static String removeAllPatternDotAll(String source, String regex) {
        return replaceAllPatternDotAll(source, regex, StringUtils.EMPTY);
    }
{code}

Patch attached. 

Feedback? Better method names?

  was:
Patch attached. 

Feedback? Better method names?

    
> Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode
> -------------------------------------------------------------------------------
>
>                 Key: LANG-841
>                 URL: https://issues.apache.org/jira/browse/LANG-841
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>         Attachments: lang-841.diff
>
>
> I often want to call:
> {code:java}
> "OldValue\nOldValue".replaceAll("Regex", "NewValue")
> {code}
> where the old value has end of line chars. So I need to do this:
> {code:java}
> Pattern.compile("Regex", Pattern.DOTALL).matcher("OldValue\nOldValue").replaceAll("NewValue");
> {code}
> which I put in a util methods, which feels like it could be in StringUtils:
> {code:java}
>     /**
>      * Replaces each substring of the source String that matches the given regular expression with the given
>      * replacement using the DOTALL option.
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @param replacement
>      *            the string to be substituted for each match
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String replaceAllPatternDotAll(String source, String regex, String replacement) {
>         return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement);
>     }
>     /**
>      * Removes each substring of the source String that matches the given regular expression using the DOTALL option.
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String removeAllPatternDotAll(String source, String regex) {
>         return replaceAllPatternDotAll(source, regex, StringUtils.EMPTY);
>     }
> {code}
> Patch attached. 
> Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (LANG-841) Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-841?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory updated LANG-841:
---------------------------------

    Description: 
I often want to call:

{code:java}
"OldValue\nOldValue".replaceAll("Regex", "NewValue")
{code}

where the old value has end of line chars. So I need to do this:

{code:java}
Pattern.compile("Regex", Pattern.DOTALL).matcher("OldValue\nOldValue").replaceAll("NewValue");
{code}

which I put in a util methods, which feels like it could be in StringUtils:

{code:java}
    /**
     * Replaces each substring of the source String that matches the given regular expression with the given
     * replacement using the {@link Pattern#DOTALL} option. DOTALL is also know as single-line mode in Perl. This call
     * is also equivalent to:
     * <ul>
     * <li>{@code source.replaceAll(&quot;(?s)&quot; + regex, replacement)}</li>
     * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}</li>
     * </ul>
     * 
     * @param source
     *            the source string
     * @param regex
     *            the regular expression to which this string is to be matched
     * @param replacement
     *            the string to be substituted for each match
     * @return The resulting {@code String}
     * @see String#replaceAll(String, String)
     * @see Pattern#DOTALL
     * @since 3.2
     */
    public static String replaceAllPatternDotAll(String source, String regex, String replacement) {
        return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement);
    }

    /**
     * Removes each substring of the source String that matches the given regular expression using the DOTALL option.
     * 
     * @param source
     *            the source string
     * @param regex
     *            the regular expression to which this string is to be matched
     * @return The resulting {@code String}
     * @see String#replaceAll(String, String)
     * @see Pattern#DOTALL
     * @since 3.2
     */
    public static String removeAllPatternDotAll(String source, String regex) {
        return replaceAllPatternDotAll(source, regex, StringUtils.EMPTY);
    }
{code}

Patch attached. 

Feedback? Better method names?

  was:
I often want to call:

{code:java}
"OldValue\nOldValue".replaceAll("Regex", "NewValue")
{code}

where the old value has end of line chars. So I need to do this:

{code:java}
Pattern.compile("Regex", Pattern.DOTALL).matcher("OldValue\nOldValue").replaceAll("NewValue");
{code}

which I put in a util methods, which feels like it could be in StringUtils:

{code:java}
    /**
     * Replaces each substring of the source String that matches the given regular expression with the given
     * replacement using the DOTALL option.
     * 
     * @param source
     *            the source string
     * @param regex
     *            the regular expression to which this string is to be matched
     * @param replacement
     *            the string to be substituted for each match
     * @return The resulting {@code String}
     * @see String#replaceAll(String, String)
     * @see Pattern#DOTALL
     * @since 3.2
     */
    public static String replaceAllPatternDotAll(String source, String regex, String replacement) {
        return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement);
    }

    /**
     * Removes each substring of the source String that matches the given regular expression using the DOTALL option.
     * 
     * @param source
     *            the source string
     * @param regex
     *            the regular expression to which this string is to be matched
     * @return The resulting {@code String}
     * @see String#replaceAll(String, String)
     * @see Pattern#DOTALL
     * @since 3.2
     */
    public static String removeAllPatternDotAll(String source, String regex) {
        return replaceAllPatternDotAll(source, regex, StringUtils.EMPTY);
    }
{code}

Patch attached. 

Feedback? Better method names?

    
> Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode
> -------------------------------------------------------------------------------
>
>                 Key: LANG-841
>                 URL: https://issues.apache.org/jira/browse/LANG-841
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>
> I often want to call:
> {code:java}
> "OldValue\nOldValue".replaceAll("Regex", "NewValue")
> {code}
> where the old value has end of line chars. So I need to do this:
> {code:java}
> Pattern.compile("Regex", Pattern.DOTALL).matcher("OldValue\nOldValue").replaceAll("NewValue");
> {code}
> which I put in a util methods, which feels like it could be in StringUtils:
> {code:java}
>     /**
>      * Replaces each substring of the source String that matches the given regular expression with the given
>      * replacement using the {@link Pattern#DOTALL} option. DOTALL is also know as single-line mode in Perl. This call
>      * is also equivalent to:
>      * <ul>
>      * <li>{@code source.replaceAll(&quot;(?s)&quot; + regex, replacement)}</li>
>      * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}</li>
>      * </ul>
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @param replacement
>      *            the string to be substituted for each match
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String replaceAllPatternDotAll(String source, String regex, String replacement) {
>         return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement);
>     }
>     /**
>      * Removes each substring of the source String that matches the given regular expression using the DOTALL option.
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String removeAllPatternDotAll(String source, String regex) {
>         return replaceAllPatternDotAll(source, regex, StringUtils.EMPTY);
>     }
> {code}
> Patch attached. 
> Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Comment Edited] (LANG-841) Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13471609#comment-13471609 ] 

Gary D. Gregory edited comment on LANG-841 at 10/8/12 3:18 PM:
---------------------------------------------------------------

Hm, "All" and "Entire" next to each other look weird, especially because they are synonymous.

I used the word Pattern to differentiate the method from the other replace methods that do NOT take a Regex:

- replace(String, String, String)
- replace(String, String, String, int)
- replaceChars(String, char, char)
- replaceChars(String, String, String)
- replaceEach(String, String[], String[])
- replaceEach(String, String[], String[], boolean, int)
- replaceEachRepeatedly(String, String[], String[])
- replaceOnce(String, String, String)

There should be something in the name that suggest the method works with a Regex.

I also used the word Pattern because the underlying Java class is Pattern. Using "Regex" is also possible but not better than Pattern IMO.

Maybe we should flip it where we assume that the API searches the whole String, like the other APIs, the only difference is that a Regex is used for matching. If you don't want to search the whole String, then you do not need this API! 

So we already have:

replace(String, String, String) for non-regex

and then we have the new:

replacePattern(String, String, String) for using regex and the Pattern class!

I like it much better!

                
      was (Author: garydgregory):
    Hm, "All" and "Entire" next to each other look weird, especially because they are synonymous.

I used the word Pattern to differentiate the method from the other replace methods that do NOT take a Regex:

- replace(String, String, String)
- replace(String, String, String, int)
- replaceChars(String, char, char)
- replaceChars(String, String, String)
- replaceEach(String, String[], String[])
- replaceEach(String, String[], String[], boolean, int)
- replaceEachRepeatedly(String, String[], String[])
- replaceOnce(String, String, String)

There should be something in the name that suggest the method works with a Regex.

I also used the word Pattern because the underlying Java class is Pattern. Using "Regex" is also possible but not better than Pattern IMO.

Maybe we should flip it where we assume that the API searches the whole String, like the other APIs, the only difference is that a Regex is used for matching. If you don't want to search the whole String, then you do not need this API! 

So we already have:

replace(String, String, String) for non-regex

replacePattern(String, String, String) for using regex and the Pattern class!

I like it much better!

                  
> Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode
> -------------------------------------------------------------------------------
>
>                 Key: LANG-841
>                 URL: https://issues.apache.org/jira/browse/LANG-841
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>         Attachments: lang-841-v3.diff
>
>
> I often want to call:
> {code:java}
> "OldValue\nOldValue".replaceAll("Regex", "NewValue")
> {code}
> where the old value has end of line chars. So I need to do this:
> {code:java}
> Pattern.compile("Regex", Pattern.DOTALL).matcher("OldValue\nOldValue").replaceAll("NewValue");
> {code}
> which I put in a util methods, which feels like it could be in StringUtils:
> {code:java}
>     /**
>      * Replaces each substring of the source String that matches the given regular expression with the given
>      * replacement using the {@link Pattern#DOTALL} option. DOTALL is also know as single-line mode in Perl. This call
>      * is also equivalent to:
>      * <ul>
>      * <li>{@code source.replaceAll(&quot;(?s)&quot; + regex, replacement)}</li>
>      * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}</li>
>      * </ul>
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @param replacement
>      *            the string to be substituted for each match
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String replaceAllPatternDotAll(String source, String regex, String replacement) {
>         return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement);
>     }
>     /**
>      * Removes each substring of the source String that matches the given regular expression using the DOTALL option.
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String removeAllPatternDotAll(String source, String regex) {
>         return replaceAllPatternDotAll(source, regex, StringUtils.EMPTY);
>     }
> {code}
> Patch attached. 
> Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (LANG-841) Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-841?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory updated LANG-841:
---------------------------------

    Attachment: lang-841-v3.diff
    
> Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode
> -------------------------------------------------------------------------------
>
>                 Key: LANG-841
>                 URL: https://issues.apache.org/jira/browse/LANG-841
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>         Attachments: lang-841-v3.diff
>
>
> I often want to call:
> {code:java}
> "OldValue\nOldValue".replaceAll("Regex", "NewValue")
> {code}
> where the old value has end of line chars. So I need to do this:
> {code:java}
> Pattern.compile("Regex", Pattern.DOTALL).matcher("OldValue\nOldValue").replaceAll("NewValue");
> {code}
> which I put in a util methods, which feels like it could be in StringUtils:
> {code:java}
>     /**
>      * Replaces each substring of the source String that matches the given regular expression with the given
>      * replacement using the {@link Pattern#DOTALL} option. DOTALL is also know as single-line mode in Perl. This call
>      * is also equivalent to:
>      * <ul>
>      * <li>{@code source.replaceAll(&quot;(?s)&quot; + regex, replacement)}</li>
>      * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}</li>
>      * </ul>
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @param replacement
>      *            the string to be substituted for each match
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String replaceAllPatternDotAll(String source, String regex, String replacement) {
>         return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement);
>     }
>     /**
>      * Removes each substring of the source String that matches the given regular expression using the DOTALL option.
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String removeAllPatternDotAll(String source, String regex) {
>         return replaceAllPatternDotAll(source, regex, StringUtils.EMPTY);
>     }
> {code}
> Patch attached. 
> Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-841) Add StringUtils replaceAllPatternDotAll and removeAllPatternDotAll

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13470193#comment-13470193 ] 

Sebb commented on LANG-841:
---------------------------

JIRA description too terse - please explain purpose don't have to read patch.

Also, DOTALL is not an obvious name.
Might be worth stating in Javadoc that DOTALL means the same as Perl 'single-line' mode, i.e.
    removeAllPatternDotAll(source, regex, replacement)
has the same effect as
    source.replaceAll("(?s)"+regex, replacement);
                
> Add StringUtils replaceAllPatternDotAll and removeAllPatternDotAll
> ------------------------------------------------------------------
>
>                 Key: LANG-841
>                 URL: https://issues.apache.org/jira/browse/LANG-841
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>         Attachments: lang-841.diff
>
>
> Patch attached. 
> Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (LANG-841) Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-841?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory updated LANG-841:
---------------------------------

    Attachment:     (was: lang-841.diff)
    
> Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode
> -------------------------------------------------------------------------------
>
>                 Key: LANG-841
>                 URL: https://issues.apache.org/jira/browse/LANG-841
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>         Attachments: lang-841-v3.diff
>
>
> I often want to call:
> {code:java}
> "OldValue\nOldValue".replaceAll("Regex", "NewValue")
> {code}
> where the old value has end of line chars. So I need to do this:
> {code:java}
> Pattern.compile("Regex", Pattern.DOTALL).matcher("OldValue\nOldValue").replaceAll("NewValue");
> {code}
> which I put in a util methods, which feels like it could be in StringUtils:
> {code:java}
>     /**
>      * Replaces each substring of the source String that matches the given regular expression with the given
>      * replacement using the {@link Pattern#DOTALL} option. DOTALL is also know as single-line mode in Perl. This call
>      * is also equivalent to:
>      * <ul>
>      * <li>{@code source.replaceAll(&quot;(?s)&quot; + regex, replacement)}</li>
>      * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}</li>
>      * </ul>
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @param replacement
>      *            the string to be substituted for each match
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String replaceAllPatternDotAll(String source, String regex, String replacement) {
>         return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement);
>     }
>     /**
>      * Removes each substring of the source String that matches the given regular expression using the DOTALL option.
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String removeAllPatternDotAll(String source, String regex) {
>         return replaceAllPatternDotAll(source, regex, StringUtils.EMPTY);
>     }
> {code}
> Patch attached. 
> Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-841) Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13471609#comment-13471609 ] 

Gary D. Gregory commented on LANG-841:
--------------------------------------

Hm, "All" and "Entire" next to each other look weird, especially because they are synonymous.

I used the word Pattern to differentiate the method from the other replace methods that do NOT take a Regex:

- replace(String, String, String)
- replace(String, String, String, int)
- replaceChars(String, char, char)
- replaceChars(String, String, String)
- replaceEach(String, String[], String[])
- replaceEach(String, String[], String[], boolean, int)
- replaceEachRepeatedly(String, String[], String[])
- replaceOnce(String, String, String)

There should be something in the name that suggest the method works with a Regex.

I also used the word Pattern because the underlying Java class is Pattern. Using "Regex" is also possible but not better than Pattern IMO.

Maybe we should flip it where we assume that the API searches the whole String, like the other APIs, the only difference is that a Regex is used for matching. If you don't want to search the whole String, then you do not need this API! 

So we already have:

replace(String, String, String) for non-regex

replacePattern(String, String, String) for using regex and the Pattern class!

I like it much better!

                
> Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode
> -------------------------------------------------------------------------------
>
>                 Key: LANG-841
>                 URL: https://issues.apache.org/jira/browse/LANG-841
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>         Attachments: lang-841.diff
>
>
> I often want to call:
> {code:java}
> "OldValue\nOldValue".replaceAll("Regex", "NewValue")
> {code}
> where the old value has end of line chars. So I need to do this:
> {code:java}
> Pattern.compile("Regex", Pattern.DOTALL).matcher("OldValue\nOldValue").replaceAll("NewValue");
> {code}
> which I put in a util methods, which feels like it could be in StringUtils:
> {code:java}
>     /**
>      * Replaces each substring of the source String that matches the given regular expression with the given
>      * replacement using the {@link Pattern#DOTALL} option. DOTALL is also know as single-line mode in Perl. This call
>      * is also equivalent to:
>      * <ul>
>      * <li>{@code source.replaceAll(&quot;(?s)&quot; + regex, replacement)}</li>
>      * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}</li>
>      * </ul>
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @param replacement
>      *            the string to be substituted for each match
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String replaceAllPatternDotAll(String source, String regex, String replacement) {
>         return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement);
>     }
>     /**
>      * Removes each substring of the source String that matches the given regular expression using the DOTALL option.
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String removeAllPatternDotAll(String source, String regex) {
>         return replaceAllPatternDotAll(source, regex, StringUtils.EMPTY);
>     }
> {code}
> Patch attached. 
> Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-841) Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode

Posted by "Duncan Jones (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13471627#comment-13471627 ] 

Duncan Jones commented on LANG-841:
-----------------------------------

{quote}So we already have:

replace(String, String, String) for non-regex

and then we have the new:

replacePattern(String, String, String) for using regex and the Pattern class!

I like it much better!{quote}

Sounds good to me!
                
> Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode
> -------------------------------------------------------------------------------
>
>                 Key: LANG-841
>                 URL: https://issues.apache.org/jira/browse/LANG-841
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>         Attachments: lang-841-v3.diff
>
>
> I often want to call:
> {code:java}
> "OldValue\nOldValue".replaceAll("Regex", "NewValue")
> {code}
> where the old value has end of line chars. So I need to do this:
> {code:java}
> Pattern.compile("Regex", Pattern.DOTALL).matcher("OldValue\nOldValue").replaceAll("NewValue");
> {code}
> which I put in a util methods, which feels like it could be in StringUtils:
> {code:java}
>     /**
>      * Replaces each substring of the source String that matches the given regular expression with the given
>      * replacement using the {@link Pattern#DOTALL} option. DOTALL is also know as single-line mode in Perl. This call
>      * is also equivalent to:
>      * <ul>
>      * <li>{@code source.replaceAll(&quot;(?s)&quot; + regex, replacement)}</li>
>      * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}</li>
>      * </ul>
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @param replacement
>      *            the string to be substituted for each match
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String replaceAllPatternDotAll(String source, String regex, String replacement) {
>         return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement);
>     }
>     /**
>      * Removes each substring of the source String that matches the given regular expression using the DOTALL option.
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String removeAllPatternDotAll(String source, String regex) {
>         return replaceAllPatternDotAll(source, regex, StringUtils.EMPTY);
>     }
> {code}
> Patch attached. 
> Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-841) Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode

Posted by "Duncan Jones (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13471435#comment-13471435 ] 

Duncan Jones commented on LANG-841:
-----------------------------------

bq. I am still looking for better API names.

How about {{replaceAllEntireString / removeAllEntireString}} ?

Also, is it worth adding single-replacement versions of these methods to match with {{String.replaceFirst}}?
                
> Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode
> -------------------------------------------------------------------------------
>
>                 Key: LANG-841
>                 URL: https://issues.apache.org/jira/browse/LANG-841
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>         Attachments: lang-841.diff
>
>
> I often want to call:
> {code:java}
> "OldValue\nOldValue".replaceAll("Regex", "NewValue")
> {code}
> where the old value has end of line chars. So I need to do this:
> {code:java}
> Pattern.compile("Regex", Pattern.DOTALL).matcher("OldValue\nOldValue").replaceAll("NewValue");
> {code}
> which I put in a util methods, which feels like it could be in StringUtils:
> {code:java}
>     /**
>      * Replaces each substring of the source String that matches the given regular expression with the given
>      * replacement using the {@link Pattern#DOTALL} option. DOTALL is also know as single-line mode in Perl. This call
>      * is also equivalent to:
>      * <ul>
>      * <li>{@code source.replaceAll(&quot;(?s)&quot; + regex, replacement)}</li>
>      * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}</li>
>      * </ul>
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @param replacement
>      *            the string to be substituted for each match
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String replaceAllPatternDotAll(String source, String regex, String replacement) {
>         return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement);
>     }
>     /**
>      * Removes each substring of the source String that matches the given regular expression using the DOTALL option.
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String removeAllPatternDotAll(String source, String regex) {
>         return replaceAllPatternDotAll(source, regex, StringUtils.EMPTY);
>     }
> {code}
> Patch attached. 
> Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (LANG-841) Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-841?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory updated LANG-841:
---------------------------------

    Attachment:     (was: lang-841.diff)
    
> Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode
> -------------------------------------------------------------------------------
>
>                 Key: LANG-841
>                 URL: https://issues.apache.org/jira/browse/LANG-841
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>
> I often want to call:
> {code:java}
> "OldValue\nOldValue".replaceAll("Regex", "NewValue")
> {code}
> where the old value has end of line chars. So I need to do this:
> {code:java}
> Pattern.compile("Regex", Pattern.DOTALL).matcher("OldValue\nOldValue").replaceAll("NewValue");
> {code}
> which I put in a util methods, which feels like it could be in StringUtils:
> {code:java}
>     /**
>      * Replaces each substring of the source String that matches the given regular expression with the given
>      * replacement using the {@link Pattern#DOTALL} option. DOTALL is also know as single-line mode in Perl. This call
>      * is also equivalent to:
>      * <ul>
>      * <li>{@code source.replaceAll(&quot;(?s)&quot; + regex, replacement)}</li>
>      * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}</li>
>      * </ul>
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @param replacement
>      *            the string to be substituted for each match
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String replaceAllPatternDotAll(String source, String regex, String replacement) {
>         return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement);
>     }
>     /**
>      * Removes each substring of the source String that matches the given regular expression using the DOTALL option.
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String removeAllPatternDotAll(String source, String regex) {
>         return replaceAllPatternDotAll(source, regex, StringUtils.EMPTY);
>     }
> {code}
> Patch attached. 
> Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (LANG-841) Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-841?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory updated LANG-841:
---------------------------------

    Attachment: lang-841.diff

v2 of the patch.
                
> Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode
> -------------------------------------------------------------------------------
>
>                 Key: LANG-841
>                 URL: https://issues.apache.org/jira/browse/LANG-841
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>         Attachments: lang-841.diff
>
>
> I often want to call:
> {code:java}
> "OldValue\nOldValue".replaceAll("Regex", "NewValue")
> {code}
> where the old value has end of line chars. So I need to do this:
> {code:java}
> Pattern.compile("Regex", Pattern.DOTALL).matcher("OldValue\nOldValue").replaceAll("NewValue");
> {code}
> which I put in a util methods, which feels like it could be in StringUtils:
> {code:java}
>     /**
>      * Replaces each substring of the source String that matches the given regular expression with the given
>      * replacement using the {@link Pattern#DOTALL} option. DOTALL is also know as single-line mode in Perl. This call
>      * is also equivalent to:
>      * <ul>
>      * <li>{@code source.replaceAll(&quot;(?s)&quot; + regex, replacement)}</li>
>      * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}</li>
>      * </ul>
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @param replacement
>      *            the string to be substituted for each match
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String replaceAllPatternDotAll(String source, String regex, String replacement) {
>         return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement);
>     }
>     /**
>      * Removes each substring of the source String that matches the given regular expression using the DOTALL option.
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String removeAllPatternDotAll(String source, String regex) {
>         return replaceAllPatternDotAll(source, regex, StringUtils.EMPTY);
>     }
> {code}
> Patch attached. 
> Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (LANG-841) Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-841?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory updated LANG-841:
---------------------------------

    Summary: Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode  (was: Add StringUtils replaceAllPatternDotAll and removeAllPatternDotAll)
    
> Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode
> -------------------------------------------------------------------------------
>
>                 Key: LANG-841
>                 URL: https://issues.apache.org/jira/browse/LANG-841
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>         Attachments: lang-841.diff
>
>
> Patch attached. 
> Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LANG-841) Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13470335#comment-13470335 ] 

Gary D. Gregory commented on LANG-841:
--------------------------------------

I updated the ticket title and description to be much more detailed. The v2 patch reflects the changes.

I am still looking for better API names.
                
> Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode
> -------------------------------------------------------------------------------
>
>                 Key: LANG-841
>                 URL: https://issues.apache.org/jira/browse/LANG-841
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>         Attachments: lang-841.diff
>
>
> I often want to call:
> {code:java}
> "OldValue\nOldValue".replaceAll("Regex", "NewValue")
> {code}
> where the old value has end of line chars. So I need to do this:
> {code:java}
> Pattern.compile("Regex", Pattern.DOTALL).matcher("OldValue\nOldValue").replaceAll("NewValue");
> {code}
> which I put in a util methods, which feels like it could be in StringUtils:
> {code:java}
>     /**
>      * Replaces each substring of the source String that matches the given regular expression with the given
>      * replacement using the {@link Pattern#DOTALL} option. DOTALL is also know as single-line mode in Perl. This call
>      * is also equivalent to:
>      * <ul>
>      * <li>{@code source.replaceAll(&quot;(?s)&quot; + regex, replacement)}</li>
>      * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}</li>
>      * </ul>
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @param replacement
>      *            the string to be substituted for each match
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String replaceAllPatternDotAll(String source, String regex, String replacement) {
>         return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement);
>     }
>     /**
>      * Removes each substring of the source String that matches the given regular expression using the DOTALL option.
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String removeAllPatternDotAll(String source, String regex) {
>         return replaceAllPatternDotAll(source, regex, StringUtils.EMPTY);
>     }
> {code}
> Patch attached. 
> Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Resolved] (LANG-841) Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-841?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory resolved LANG-841.
----------------------------------

       Resolution: Fixed
    Fix Version/s: 3.2
    
> Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode
> -------------------------------------------------------------------------------
>
>                 Key: LANG-841
>                 URL: https://issues.apache.org/jira/browse/LANG-841
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>             Fix For: 3.2
>
>         Attachments: lang-841-v3.diff
>
>
> I often want to call:
> {code:java}
> "OldValue\nOldValue".replaceAll("Regex", "NewValue")
> {code}
> where the old value has end of line chars. So I need to do this:
> {code:java}
> Pattern.compile("Regex", Pattern.DOTALL).matcher("OldValue\nOldValue").replaceAll("NewValue");
> {code}
> which I put in a util methods, which feels like it could be in StringUtils:
> {code:java}
>     /**
>      * Replaces each substring of the source String that matches the given regular expression with the given
>      * replacement using the {@link Pattern#DOTALL} option. DOTALL is also know as single-line mode in Perl. This call
>      * is also equivalent to:
>      * <ul>
>      * <li>{@code source.replaceAll(&quot;(?s)&quot; + regex, replacement)}</li>
>      * <li>{@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}</li>
>      * </ul>
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @param replacement
>      *            the string to be substituted for each match
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String replaceAllPatternDotAll(String source, String regex, String replacement) {
>         return Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement);
>     }
>     /**
>      * Removes each substring of the source String that matches the given regular expression using the DOTALL option.
>      * 
>      * @param source
>      *            the source string
>      * @param regex
>      *            the regular expression to which this string is to be matched
>      * @return The resulting {@code String}
>      * @see String#replaceAll(String, String)
>      * @see Pattern#DOTALL
>      * @since 3.2
>      */
>     public static String removeAllPatternDotAll(String source, String regex) {
>         return replaceAllPatternDotAll(source, regex, StringUtils.EMPTY);
>     }
> {code}
> Patch attached. 
> Feedback? Better method names?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira