Re: How to exclude a sequence of characters
"Thomas Wiedmann" <[email protected]> Tue, 22 Mar 2011 08:03:39 +0100
| Newsgroups | gmane.comp.jakarta.regexp.user |
|---|---|
| Message-ID | <[email protected]> |
> It sounds like you want to use a zero-width negative lookahead assertion. > For example: > test(?!-end) > > You should probably use java.util.regex. I tried the Java statements String text = "mytest-xyz"; String pattern = ".*test(?!-end)"; System.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 done it. What's the reason? How must the RegExp statement be written, that texts like "mytext-end" are not matched, because they a excluded, but a text like "mytest-xyz" is accepted, because it doesn't end with "-end"? Thomas Wiedmann