RegEx String Negation

Hello,
I'm trying to find a regular expression that will match any file URI in the WEB-INF/lib directory and the jars within it except a couple of specific jars, let's say a.jar and b.jar.
For instance, I'd like the expression to match WEB-INF/lib/c.jar/myClass.class and WEB-INF/lib/d.jar/myClass.class but not any file inside and including the WEB-INF/lib/a.jar and WEB-INF/lib/b.jar
From what I understand so far, it would be ideal if I could somehow group a literal string "a.jar" and "b.jar" into two distinct entities, E1 and E2 and use negation brackets to something of the effect WEB-INF/lib/[^E1E2].* which would match everything that begins with WEB-INF/lib except those strings directly followed by E1 and E2, a.jar and b.jar respectively.
Is there a way to do this?

jschell wrote:
sabre150 wrote:
The fact that you can use the regex class to construct code that is processed in a loop means that what I said is exactly correct.Come off it. Why are you being so defensive and pedantic? I was expressing the view that it could be done in one stage rather than in two. If you think that your procedure outlined in reply #1 results in better code than I posted in reply #6 then post something to illustrate this.
Except that you said "There is no need for this ..."
Meaning one does not have to use an explicit loop and accept files only when the name does not match a file to be rejected. One can use a FileFilter using a negative look ahead to do the excluding. As you point out later, one could just have well used a ! operation and saved the negative look ahead.
>
Which reads as though you think that your solution is in fact better in some way than what I said and/or that what I said is incorrect.I did not say or imply that your solution is incorrect. I said "There is no need for this since one can use 'negative lookahead' to exclude files from the match." with the accent being on the word 'need'. I saw your solution in reply 1 as needing an explicit loop when one is not needed. I still read it that way.
>
Your solution is doing nothing but exactly what I said except that you use a negative case where negating a positive one would do exactly the same thing.Not unless I am totally misunderstanding what you were saying. I saw then and still do see your solution as requiring one to get a list of the files then explicitly go though the list to create a list of those that are not in the rejected set. Your solution needs an explicit loop. Mine does not require an explicit loop.
>
Modifying your code (to a semi pseudo example)...
return ! name.matches("^(a\\.jar|b\\.jar)$");Yep. I agree. But that is not what I read into reply 1. You did not mention class FileFilter. You did use the words 'file filter'. You implied an explicit loop which is not needed.
>
>>>
Because you are using the regex class and doing a comparison one file name at a time it means that a positive regex (which you negate) works just as well and probably better than negative look ahead.Again, I was just removing a processing stage.
Again which suggests that you think your solution is somehow different than what I claimed exclusive of the fact that you are using a negative case rather than negating a positive one.I just claim that your reply 1 implied an explicit loop which is not needed. If that is not what you meant then I misunderstood.
>
>>>
Now if the java API has a method that takes a regex expression and filters files names then a negative look ahead would probably be ideal.I didn't say the API did have such a class. I don't see the need for RegexFileFilter to be in the API (though I have one in my private library) since as I illustrated it is trivial to implement with the current API.Just to be clear you do understand that your solution is in fact in a loop right? Yes - but the the loop is behind the scenes hidden in the listFiles() method.
Each file individually is subjected to a regex comparison. Yes.
The implementation of the loop itself is irrelevant and specifically not detailed for reason in my response.That is all we are arguing about. I think it is very very very relevant since reply 1 implies an explicit loop is required.
>
After that the only difference is
1. Your solution uses a regex crafted to look for a negative condition
2. My uses a regex crafted to look for a positive case and then negate the result.I agree that the regex bit makes little or no difference but the explicit loop does.
>
In the above how do you think that your solution is better, more complete, or substantially different than what I proposed? Do you think that a negative regex is more expressive than negating the result? Or perhaps more efficient?I never said that. I don't say that. As I keep saying - my solution does not require an explicit loop though behind the scenes there is a loop.
>
And finally you do understand that if the Java API itself did offer a service like this then your regex would in fact be correct because such an API would very likely assume a positive match?Which is probably why I thought in terms of negative look ahead because my RegexFileFilter does look for a positive match. I also have a NotFileFilter which chains to another file filter and returns the inverse of result of the chained FileFilter.
In this case there is no such API and so in crafting such an API one can code it to use a negative match. That is specifically why I asked if such a Java API exists. It doesn't.Either I totally misunderstood reply 1 and you were not meaning that an explicit loop is required or I misunderstand the points you have been trying to make since reply 1. Either way it's not going to get resolved without both of us spending significant time on it and I don't think the rewards are going to be worth the effort. I will let you have the last word if you care to respond to this.

Similar Messages

  • HTTP probe issue with expect regex string

    Hello,
    We have a simple cgi status page setup to poll a background service and return a "PASS" or "FAIL" as output.  I've setup an HTTP probe to look for the "PASS" to determine application health.  The issue appears to be that the expect regex is searching the HEADER but not the BODY of the web page.  I can successfully match on any string in the header, but never on anything in the body.
    Here is what the web page returns if you telnet to it:
    HTTP/1.1 200 OK
    Date: Thu, 22 Sep 2011 22:45:07 GMT
    Server: Apache/2.0.59  HP-UX_Apache-based_Web_Server (Unix) DAV/2
    Content-Length: 4
    Connection: close
    Content-Type: text/plain; charset=iso-8859-1
    PASS
    Here is my probe:
    probe http JOE-TEST-CS
      interval 45
      passdetect interval 30
      receive 30
      request method get url /cgi-bin/ERMS-PREP-statusRepo.cgi
      expect status 0 999
      open 20
      expect regex "PASS"
    Here is the output of the show probe:
    ACE1/euhr-test-ace2# sh probe JOE-TEST-CS detail
    probe       : JOE-TEST-CS
    type        : HTTP
    state       : ACTIVE
    description :
       port      : 80      address     : 0.0.0.0         addr type  : -
       interval  : 45      pass intvl  : 30              pass count : 3
       fail count: 3       recv timeout: 30
       http method      : GET
       http url         : /cgi-bin/ERMS-PREP-statusRepo.cgi
       conn termination : GRACEFUL
       expect offset    : 0         , open timeout     : 20
       expect regex     : PASS
       send data        : -
                           --------------------- probe results --------------------
       probe association   probed-address  probes     failed     passed     health
       ------------------- ---------------+----------+----------+----------+-------
       serverfarm  : JOE-TEST-PROBE-CS
         real      : EUHRTDM50.APP[0]
                           192.168.73.71   2          2          0          FAILED
       Socket state        : CLOSED
       No. Passed states   : 0         No. Failed states : 1
       No. Probes skipped  : 0         Last status code  : 200
       No. Out of Sockets  : 0         No. Internal error: 0
       Last disconnect err : User defined Reg-Exp was not found in Host Response
      Last probe time     : Thu Sep 22 15:00:36 2011
       Last fail time      : Thu Sep 22 15:00:36 2011
       Last active time    : Thu Sep 22 09:40:19 2011
    If I replace the expect regex "PASS" with anything from the HEADER it succeeds!
    Any thoughts?

    Sorry, I missed it.  The content-length in your request is 4.  I think this may be the issue.  I created a basic HTML page that says PASS in the body and my server is returning a content-length of 224 when I fetch the page.  Here is my HTML request:
    GET /index.html
    http-equiv="Content-Type">
      Probe
    PASS
    Here are my headers that I received:
    (Status-Line)    HTTP/1.1 200 OK
    Content-Length    224
    Content-Type    text/html
    Last-Modified    Tue, 27 Sep 2011 12:05:00 GMT
    Accept-Ranges    bytes
    Etag    "8cca60aed7dcc1:41f"
    Server    Microsoft-IIS/6.0
    Date    Tue, 27 Sep 2011 12:25:59 GMT
    What version of code are you running on your ACE?  I can also look to see if there are any known issues.
    Kris

  • Regex, String Range

    Hello please,
    Appreciate your help here.
    I have a field string that wants to find if that exists between two range strings on character basis.
    Ex:
    String lower boundary : "ABD"
    String upper boundary : "ALGKP"
    field String : "ABE"
    Now the field string "ABE" exists between "ABD" and "ALGKP".
    Here the comparison is char-by-char. i.e
    A is b/w A & A, true
    B is b/w B and L, true
    E is b/w D and G, true
    So finally returns true.
    Another example:
    For the same above boundaries, if the field string is "ABC", it should return false since C not b/w D & G.
    For the same above boundaries, if the field string is "AB", it should return true.
    Thanks
    Dileep
    Edited by: 828040 on Jan 13, 2011 11:34 AM

    828040 wrote:
    For the same above boundaries, if the field string is "ABC", it should return false since C not b/w D & P.You mean since C is not between D and G, right?
    And I agree: Regex is absolutely NOT the way to go here. Just truncate the upper and lower boundaries to the input String's length, then use String.compareTo() to see if it's lexicographically between the boundaries.
    Edited by: jverd on Jan 13, 2011 11:21 AM

  • Return regex string

    I know how to run an regular expression and return a boolean if the pattern is matched.
    How do I return the actual string that is matched?
    e,g The is string is:
    "fasfasf safas 12345 rgrg"
    My regex matches 12345
    I want to return 12345 as a string rather than a boolean stating the match was sucesfull.
    Thanks

    jk987 wrote:
    I know how to run an regular expression and return a boolean if the pattern is matched.
    How do I return the actual string that is matched?
    e,g The is string is:
    "fasfasf safas 12345 rgrg"
    My regex matches 12345
    I want to return 12345 as a string rather than a boolean stating the match was sucesfull.
    ThanksIf your 'regex' is always a literal string, you could use String.indexOf() method. If not, try
    public class Jk987{
      public static void main(String[] args){
        String s1 = "fasfasf safas 12345 rgrg";
        String s2 = "fasfasf safas rgrg";
        String regex = ".*(12345).*";
        String res1 = s1.replaceFirst(regex, "$1");
        String res2 = s2.replaceFirst(regex, "$1");
        System.out.println(res1);
        System.out.println(res2);
    }

  • Help: String.replaceAll(regex,string) !!!

    i want to replace a string(called str) such as
    "Don't hesitate to cantact us "
    into
    "Don\'t hesitate to cantact us "
    what statment i should take ??
    i am in a Jsp page, with
    <%= str.replaceAll("'", "\'") %> or
    <%= str.replaceAll("'", "\\'") %> or
    <%= str.replaceAll("'", "\\\'") %>
    i got always wrong or unchanged string ...
    Help !!!!!!!!!!!!!!!!!!!!!!!!!

    well if your tomcat uses jdk1.4 or above you can import java.util.Regx.* and use replaceAll() method on string in your jsp page, otherwise write your own code to substring the two string & add "\" at the end of the first string then join the two substrings.

  • How to use String.replaceAll(String regex, String replacement)?

    hi,
    I'd like to use the String.replaceAll call to replace all occurrences of a pattern in a string with a string inputted from the user.
    The problem is that replaceAll seems process the replacement string first. For example, the code below won't work
    public class StringTest {
         public static void main(String [] arg) throws Exception {
              String input = "oooIoooIooo";
              input=input.replaceAll("I","\\");
              System.out.println(input);
    }So the only option seems to be to manually process the user input string into a form that can be accepted by String.replaceAll?
    The only thing I can find from looking through the API is that you'd need to convert each backslash to a double-backslash?
    is this the right thing to be doing?
    thanks,
    asjf

    just to clarify, at the moment I think the solution is to do this
    public class StringTest {
         public static void main(String [] arg) throws Exception {
              String input = "oooIoooIooo";
              String raw = "\\";
              input=input.replaceAll("I",raw.replaceAll("\\\\","\\\\\\\\"));
              System.out.println(input);
    }

  • Regex to split a String

    Hi,
    Here's a little regex problem Jos e-mailed me the other day, to which I didn't find a satisfactory answer (I found one, but it's rather verbose). Chances are that there is no short (or simple) solution, but when this is the case with a certain problem, I usually know why there is no simple solution because of some limitation with the regex flavor I am using. However, I can't think of one with this problem.
    Also note that this problem can be easily (and far more efficiently) solved by writing a custom method, but I happen to like regex and am curious to know if there's some solution to this I missed.
    So, without further a due, here is the questions:
    Split a String T into parts with a maximum size N without splitting T on a certain sub string S. In other words: try to split a String in as large as possible parts (equal or less than N) without splitting it on a certain sub string.
    You can use only one split(...) call!
    Lets say S = abc and N = 5 then here are a couple of examples:
    T            = xyabcdefgabc
    T.split(...) = [xyabc, defg, abc]
    T            = xyzabcbbzzzabcabcbcacbyyy
    T.split(...) = [xyz, abcbb, zzz, abc, abcbc, acbyy, y]
    T            = xyzzzzabcbabczabcabcabcacbyyy
    T.split(...) = [xyzzz, zabcb, abcz, abc, abc, abcac, byyy]

    uncle_alice wrote:
    Okay, I give up. I can see how to do this with find(), but not with split(). I hope you haven't been waiting for me all this time... :DTo be frank, yes I have. You, sabre and maybe Darryl (in a good mood ; )). Ah well, I am now convinced I didn't overlook some easy shortcut.
    This is what I've cooked up:
    class Main {
        public static void main(String[] args) {
            String[] tests = {"xyabcdefgabc", "xyzabcbbzzzabcabcbcacbyyy", "xyzzzzabcbabczabcabcabcacbyyy"};
            String sub = "abc";
            int max = 5;
            String regex = String.format("(?<=\\G.{%d,%d})(?=%s)|(?<=\\G.{%d})", max-sub.length()+1, max-1, sub, max);
            System.out.println("regex = "+regex+"\n");
            for(String test: tests) {
                System.out.println(test);
                System.out.println("  -> "+Arrays.toString(test.split(regex))+"\n");
    }B.t.w. uncle_alice, this *\G* (previous match) functionality, is this some Java thing or does it exist in other regex flavors as well?

  • Using Regex to find a string

    Is it viable to use regular expressions with Search "Specific Tag" (i.e.script) "With Attribute" (i.e. src) and "=" a regex string rather than an exact search term?  The Find / Replace tool seems to prevent a simple wildcard find (i.e. "searchter* for searchterm) Any insight would be appreciated.

    uneAaron wrote:
    I'm trying to replace a script source value for all instances where the value contains the string "/bbcswebdav/xid-144702_1", where the string "xid-" is followed by a different numerical value in each instance.
    The regex for finding that string is:
    \/bbcswebdav\/xid\-[\d_]+
    The numerical value contains an underscore, so the final section ( [\d_]+ ) uses a range that selects one or more numbers and/or underscores.
    Perhaps as important as identifying what you want to find is specifying how you want to replace it. Regexes can have capturing groups that can be used in the Replace field to simplify matters.

  • String.class without split(String regex)

    hello,
    This is my problem:
    I am using eclipse with j2sdk1.4.2 which
    implement
    the clase String.class with
    method replaceAll(String regex, String replacement) and
    method split(String regex)
    PAth: home_j2sdk1.4.2/jre/lib/rt.jar 25.762kb
    In this way:
    String columns[] = line.split("\t");
    for (int i=0; i<columns.length; i++)
    ws.addCell(new Label(i,row,columns.replaceAll("\"","")));
    I move the code above to websphere Application Developer 5.1.2
    which use Home_Websphere/eclipse/jre/lib/rt.jar 8.827 kb
    this jar in yours String.class not contains the
    method replaceAll(String regex, String replacement) and
    method split(String regex)
    I need to find the use my code above with that methods,
    what i need to do ???
    possible,i need to find the source to String.java of j2sdk1.4.2
    which implement the methods, but where ???
    or there is another way to do it ???
    Any help is greatly appreciated.

    If websphere is supposedly 1.4 compatible, arethey
    "allowed" to leave out methods from the JFC? Not sure what the JFC is, but no, they would not be
    allowed to leave out any methods.
    JFC - Java Foundation Classes. I think they started calling what might be considered the Java Core the JFC when they first added Swing to the distribution. Maybe the term is no longer used.
    RRD-R      
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • ..if i say : matching with regex?

    Hi,
    i've hope that this is the place to post my little question.
    i've tried many many times to matching a String alfanumerica (
    w+) with blank(
    s+) but wiht negative
    response <img class="emoticon" src="images/emoticons/plain.gif" border="0" alt="" />
    this is a main to try this "game":
    public Class Game{
    public sattic void main(String [] args){
    boolean iCanWin = true;
    String toMach = "i want win! ";
    if(iCanWin == toMatch.matches(regex))
    System.out.printl("Congratulation Thank You Very Mach");
    else
    System.out.println("Thak You!");
    thak you .

    Ops , sorry ...
    I've tried with these regex :
    String regex="^(\\w+ \\s+ \\w+ \\!)$";
    String regex2 = "^(\\w+)\\s*\\'!'$";
    but don't work :-((.

  • Using a local variable in regex portion of replaceAll(regex, replacement)

    While this works..
    output = output.replaceAll("(HED>|AUT>)(.*)(</\\1)", "$1<![CDATA[$2]]>$3");
    I'd like the list of alternation values to be contained in a variable, for example:
    String nodeLIst = "HED>|AUT>";
    output = output.replaceAll("(nodeList)(.*)(</\\1)", "$1<![CDATA[$2]]>$3");
    The extension of this would be so I can store this stuff in a db as a list and avoid compilation on change, but please don't let this muddy the waters... :)
    Any pointers are much appreciated. Links to specific reading material, etc. I've scoured Friedl's Mastering Regular Expressions to no avail. This approach is supported by some other regex engines I've used (perl, php, ORO?) but I'm new to Java.
    TIA,
    Mark

    I've scoured Friedl's Mastering Regular Expressions to no avail.Did you look on page 209? In the book, that code sample is labelled "Building Up a Regex Through Variables in Java". That should have been a clue. ^_^
    But seriously, you're probably thinking of the interpolated strings you find in scripting languages like Perl, PHP, Ruby, etc.. But that's a feature of the language itself, not the regex engine, and Java doesn't work that way. (The $1, $2, etc., in the replacement string are processed by the Matcher class, in a very limited imitation of Perl's variable interpolation).
    However, you can fake it pretty well with String's format() method:   String regex = String.format("(%s)(.*)(</\\1)", theAlternation);
      output = output.replaceAll(regex, "$1<![CDATA[$2]]>$3"); That way, you can easily escape the dynamic part, in case it might contain regex metacharacters:   String regex = String.format("(%s)(.*)(</\\1)", Pattern.quote(theAlternation));

  • What is the unicode for ''  (need it to do String.replace)

    i'm trying to use String.replace(char a, char b)
    it won't compile if i do x.replace('_', '')
    help!
    thanks!

    Are you trying to remove all occurences of the underscore character from the string? If so create a StringBuffer from the string, loop through it and remove the characters as you find them.
    If you're using JDK1.4 you should eb able to use the new String method:
    public String replaceAll(String regex,
    String replacement)

  • With regex, how can I combine backreference and repetition

    Let's say I have a four byte long input string, consisting of four hex values:  0x03 0x03 0x03 0x03
    If I use repetition in a regex string pattern: .{4}  it matches true.
    Also, if I use backreference in a new regex pattern: (.)\1\1\1  it matches true.
    But I want to combine the two.  Say that the first byte is a length byte of the following bytes.  Then I'd believe it should be possible to do this: (.).{\1}
    The thought is that the first byte is stored as "variable" \1, and reused as the repetition counter.  So in this case, all four byte strings starting with 0x03 should match true.
    But this doesn't work!
    What am I doing wrong here?  Is this just not possible?

    ojohnsen wrote:
    No RegEx experts here?
    I am not an expert, but I play one on this forum.  To show something is possible is quick, since you can demonstrate it.  To show something is impossible is a bit harder.  For now I say, not possible.  And you do realize that .{4} will match any four character string, not anything repeated four times, right?
    That said, it sounds like you know the format of your string, so perhaps a regex would not be your first choice.  You could split a string, read the first byte, then construct a regex like ^(.)\1{length-1} and see if the remainder of the string begins with a value repeated length times.

  • Parse a string to remove character

    Hi,
    Can you please help. I have a string like "1a" or "12c". Is there a way I can parse this to remove the character values, leaving "1" and "12"
    Many Thanks

    By using
    [url=http://java.sun.com/j2se/1.4.2/docs/api/java/lang
    /String.html#replaceAll(java.lang.String,
    java.lang.String)]String.replaceAll(String regex,
    String replacement)To remove all non-digit
    characters:replaceAll("\\D+", "");Or to remove all
    letters:replaceAll("\\p{L}+",
    "")(Check
    [url=http://java.sun.com/j2se/1.4.2/docs/api/java/util
    /regex/Pattern.html]Pattern doc if you want to
    refine it.)
    Also, you should note that String.replaceAll does not modify the Original string, it returns a NEW string with the modified value. A string is technically immutable.
    so you want the code to be something like:
    String cleanString = String.replaceAll( whichever pattern you choose );
    - Adam

  • Using backreferences in String.replaceAll()

    hi, i have a string (retrieved from a JTextField), that i'd like to run through a regex Pattern, but first I'd need to escape ANY non-alphanumeric characters. i thought i could use the String class' replaceAll method, to replace each matching character with a backslash, plus \1 (a backreference to the matching character), but \1 in the second (replacement) string doesnt seem to return the matching character from the first (regex) string....how would i determine then, which character matched the pattern?
    for instance, i grab the string "full[win32]" from a JTextField, and i want to escape anything that isnt a letter or number, and end up with "full\[win32\]".

    Okay, this seems to work. You use the $ sign, not the \, in the replacement string to refer to a capturing group. And you want the replacement string to have \\$1. You need \\ so that the \ escapes the next \ and becomes a literal \ in the output. If it was a single \, then it would escape the $, and $1 wouldn't be interpreted as a reference to a capturing group. It would be taken as the literal $ followed by 1.
    Finally, since \ is an escape char in Java String literals, it has to be escaped by \ so you end up with \\\\$1, which gets fed to the Matcher as \\$1, which means "literal \ followed by capturing group 1".
    newStr = oldStr.replaceAll("([^\\p{Alnum}])", "\\\\$1");

Maybe you are looking for

  • Bill of Lading field in VL06I

    Dear MM Gurus, I am capturing the Bill of Lading Number in the 'Header > Shipment > Bill of Lading field', T/code: VL31N.  But when I execute the report VL06I the field Bill of Lading is not available.  Can anybody please advise how to bring the fiel

  • Vendor Capacity

    Hi! i would like to know if some of you guys have developed a program where in before you can create a PO for a particular vendor it will prompt (warning not error msg) you that additonal PO quanity has exceeded the total quantites (regardless of UOM

  • Windows 7 system only recognizing 16GB out of 32GB newly installed

    Hi all, I'm having some difficulties with a newly built Windows 7 system, particularly with the RAM. The problem is I have installed 32GB of memory (8 x 4GB), but Windows is only recognizing 16GB. My motherboard is an ASUS P9X79 WS. I have verified t

  • Create new album, but not show on top of page?

    I haven't worked on this website, or iweb in so long, I can't remember how... I have a website with a few different people, we all have our own albums of pic's. Our names are displayed on the top of the pages, when you click on our name, go's to our

  • Result recording(QM) - Status check error

    Hi Friends, I can not perform Result recording(QE01) due to "status Check Error". Inspection lot was created through GR. And then i tried to do Result recording. But i am getting error "status check error-This function you selected cannotbe carried o