Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!nuzba.szn.dk!pnx.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Regex: Any character in character class Date: Sat, 02 Feb 2013 00:08:28 +0100 Lines: 65 Message-ID: References: <5109e49b$0$295$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: individual.net lBIs4tLHBLYAiyoeWIsOYQOjyiZyl/Mxt+vX0P1RHwtiN5XWAT7nyi9+GM02qOCU0= Cancel-Lock: sha1:YWJzB3vpFF05nqZqGjAs9+IcZYk= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:21984 On 01.02.2013 21:14, Sebastian wrote: > Am 31.01.2013 04:27, schrieb Arne Vajh=F8j: >> On 1/30/2013 4:34 AM, Sebastian wrote: >>> I want to match any sequence of characters, including line breaks, in= a >>> suffix of a multi-line string. >>> >>> I do not want to use Pattern.DOTALL, because line breaks are not >>> permissible everywhere. I cannot write [.]* because dot loses its >>> special meaning inside a character class. >>> >>> I have come up with [\S\s]* >>> as meaning any sequence of non-whitespace or whitespace (incl. >>> line-breaks). Is there a better way? Yes. >> Do you always want to accept line breaks or not? If not then when? > the string I want to match basicallyhas two parts (a "protocol" and a > "selection expression"). I want to allow line breaks anywhere in the > selection expression, but not in the protocol. Of course you can use DOTALL - as an embedded flag: package rx; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Dotty { private static final Pattern PAT =3D Pattern.compile("proto.*(?s:sel.*)"); public static void main(String[] args) { test("protoPselS"); test("protoPPselS\nS"); test("protoP\nPselS\nS"); } public static void test(final CharSequence cs) { System.out.println("cs=3D\"" + cs + "\""); final Matcher m =3D PAT.matcher(cs); if (m.matches()) { System.out.println("Match: \"" + m.group() + "\""); } else { System.out.println("Mismatch"); } System.out.println(); } } Kind regards robert --=20 remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/