Re: How to exclude a sequence of characters

Jon Gorrono <[email protected]> Tue, 22 Mar 2011 09:58:35 -0700
Newsgroups gmane.comp.jakarta.regexp.user
Message-ID <[email protected]>
'-xyz' literal does not match the '-end' literal... if you want to
match any three-character ending you'll need something like '-...' in
the regexp

Also, I can't recall of the dash needs to be escaped outside a
square-bracket operator pair, but it might be interpreted as a range
operator here.


On Tue, Mar 22, 2011 at 12:03 AM, Thomas Wiedmann <[email protected]> wrote:
>> It sounds like you want to use a zero-width negative lookahead assertion=
.
>> For example:
>> =A0test(?!-end)
>>
>> You should probably use java.util.regex.
>
> I tried the Java statements
>
> =A0String text =3D "mytest-xyz";
> =A0String pattern =3D ".*test(?!-end)";
> =A0System.out.println(text.matches(pattern) ? "Ok" : "NOk");
>
> Unfortunately in this case "NOk" was returned. I thought the Java RegExp
> would support negative lookaheads; according to the javadoc it must had d=
one
> it.
> What's the reason?
> How must the RegExp statement be written, that texts like "mytext-end" ar=
e
> not matched, because they a excluded, but a text like "mytest-xyz" is
> accepted, because it doesn't end with "-end"?
>
> Thomas Wiedmann
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>



--=20
Jon Gorrono
PGP Key: 0x5434509D -
http{pgp.mit.edu:11371/pks/lookup?search=3D0x5434509D&op=3Dindex}
GSWoT Introducer - {GSWoT:US75 5434509D Jon P. Gorrono <jpgorrono - gswot.o=
rg>}
http{sysdev.ucdavis.edu}