Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D4C679C40 for ; Mon, 8 Oct 2012 15:18:04 +0000 (UTC) Received: (qmail 86664 invoked by uid 500); 8 Oct 2012 15:18:03 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 86575 invoked by uid 500); 8 Oct 2012 15:18:03 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 86541 invoked by uid 99); 8 Oct 2012 15:18:03 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Oct 2012 15:18:03 +0000 Date: Mon, 8 Oct 2012 15:18:03 +0000 (UTC) From: "Gary D. Gregory (JIRA)" To: issues@commons.apache.org Message-ID: <1007731951.8896.1349709483587.JavaMail.jiratomcat@arcas> In-Reply-To: <440719665.3572.1349399387285.JavaMail.jiratomcat@arcas> Subject: [jira] [Updated] (LANG-841) Add StringUtils API to call String.replaceAll in DOTALL a.k.a. single-line mode MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ 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: > *
    > *
  • {@code source.replaceAll("(?s)" + regex, replacement)}
  • > *
  • {@code Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(replacement)}
  • > *
> * > * @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