Re: How to exclude a sequence of characters
In message , "Thomas Wiedmann" writes: >May be, but what's the solution, i. e. how must the RegExp statement be >written, that texts like "mytext-end" are not matched? I already answered your question. You confirmed firsthand that jakarta regexp does not support negative lookahead assertions (and I can find no trace in the javadocs suggesting it does). If you can't switch to an API that supports the construct, there is no single regular expression you can write that will perform the match you desire. You will have to write a loop that searches for the prefix and then looks ahead to check for the undesired suffix after each match. As I said before: "oro and java.util.regex implement zero-width negative lookahead assertions. You should probably use java.util.regex." good luck, daniel - To unsubscribe, e-mail: regexp-user-unsubscr...@jakarta.apache.org For additional commands, e-mail: regexp-user-h...@jakarta.apache.org
Re: How to exclude a sequence of characters
"Jon Gorrono" schrieb im Newsbeitrag news:AANLkTik9Khsh_MqmFaBD2DB7v9L8pz=qirr8eh93n...@mail.gmail.com... '-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. May be, but what's the solution, i. e. how must the RegExp statement be written, that texts like "mytext-end" are not matched? Thomas Wiedmann - To unsubscribe, e-mail: regexp-user-unsubscr...@jakarta.apache.org For additional commands, e-mail: regexp-user-h...@jakarta.apache.org
Re: How to exclude a sequence of characters
'-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 wrote: >> 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 > > > > > - > To unsubscribe, e-mail: regexp-user-unsubscr...@jakarta.apache.org > For additional commands, e-mail: regexp-user-h...@jakarta.apache.org > > -- Jon Gorrono PGP Key: 0x5434509D - http{pgp.mit.edu:11371/pks/lookup?search=0x5434509D&op=index} GSWoT Introducer - {GSWoT:US75 5434509D Jon P. Gorrono } http{sysdev.ucdavis.edu} - To unsubscribe, e-mail: regexp-user-unsubscr...@jakarta.apache.org For additional commands, e-mail: regexp-user-h...@jakarta.apache.org
Re: How to exclude a sequence of characters
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 - To unsubscribe, e-mail: regexp-user-unsubscr...@jakarta.apache.org For additional commands, e-mail: regexp-user-h...@jakarta.apache.org
Re: How to exclude a sequence of characters
In message , "Thomas Wiedmann" writes: >Example: Trying to get all matches of the pattern 'test' but excluding all >matches of the pattern '-end', i. e. if the text contains 'test-end' this >text location should not be matched. > >By which regular expression can this search condition be realized? It sounds like you want to use a zero-width negative lookahead assertion. For example: test(?!-end) I don't believe this is something Jakarta regexp supports. oro and java.util.regex implement zero-width negative lookahead assertions. You should probably use java.util.regex. daniel - To unsubscribe, e-mail: regexp-user-unsubscr...@jakarta.apache.org For additional commands, e-mail: regexp-user-h...@jakarta.apache.org
How to exclude a sequence of characters
Hello, I'm looking for an appropriate regular expression to search a certain pattern, but to exclude a special sequence of characters. Example: Trying to get all matches of the pattern 'test' but excluding all matches of the pattern '-end', i. e. if the text contains 'test-end' this text location should not be matched. By which regular expression can this search condition be realized? Thomas Wiedmann - To unsubscribe, e-mail: regexp-user-unsubscr...@jakarta.apache.org For additional commands, e-mail: regexp-user-h...@jakarta.apache.org