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

Similar Messages

  • CSS Troubleshooting "advanced-balance url" based on string-range

    Hi together,
    a questions for troubleshooting "string range stickyness".
    I configured a content rule:
    content L5_HTTP_81
    vip address 192.168.1.1
    balance aca
    no persistent
    protocol tcp
    port 81
    url "/*"
    advanced-balance url
    add service service1 weight 1
    add service service2 weight 1
    string range 30 to 255
    string eos-char "_"
    string prefix "shopId="
    active
    service service1
    ip address 10.1.128.23
    keepalive maxfailure 2
    protocol tcp
    redundant-index 2102
    keepalive frequency 15
    keepalive retryperiod 10
    keepalive type http
    keepalive port 80
    keepalive method get
    keepalive uri "/admin/Ping.simple"
    string 148.49
    port 80
    active
    service service2
    ip address 10.1.128.22
    keepalive maxfailure 2
    protocol tcp
    redundant-index 2101
    keepalive type http
    keepalive method get
    keepalive frequency 15
    keepalive retryperiod 10
    keepalive port 80
    keepalive uri "/admin/Ping.simple"
    string 148.48
    port 80
    active
    1. I take a string from the 30rd to 255 character out of the URL starting at "/".
    2. Now I search for a string between "shop_Id=" and "_", on which the stickyness is based.
    3. string "148.49" is allocated to service1, string "148.48" is allocated to service2.
    Is there any possibillity to view or debug the handling, how the string is matched in the http request and on which service the request is forwarded ?
    thanks in advance
    sascha

    Here is the command reference. take a look at the available commands.
    http://www.cisco.com/univercd/cc/td/doc/product/webscale/css/css_710/cmdrefgd/index.htm

  • Do arrowpoint-cookies use "string range"?

    I can't find any document mentioning whether or not "advanced-balance arrowpoint-cookie" uses the "string range" setting in a content rule to determine how far to look down the cookie string to find the ARPT cookie. The default setting in the rule is "1 to 100", so if I have a cookie string that looks like this (from a sniffer trace):
    HTTP: 12: Cookie: $Version=0; XSESSIONID=Qy8PilVehwrIFD8Fs6tqzbIhtSFe3Qer9Euu2qGE4Ygz1nx29238F0FuFPS!=1730213783!=2102771864!8161!7002; ARPT=OZOMIVS172.16.1.20CK00J; preloginFlag=yes; termsflag=yes
    The arrowpoint cookie ARPT is more than 100 characters into the string, so will the CSS not see this cookie and send a new one (thereby rebalancing, possibly to a new server)? Or does advanced-balance arrowpoint-cookie always look through the entire cookie string?
    I haven't been able to lab test this, so I was wondering if anyone knew for sure?
    Thanks,
    Paul

    Paul,
    for arrowpoint cookie the CSS will look in the first 6 packets - whatever the size.
    You can increase or decrease this value with the command
    CSS11503(config)# spanning-packets ?
    Integer value(Range: 1-20)
    The string range has no effect for arrowpoint-cookie.
    Regards,
    Gilles.
    Thanks for rating this answer.

  • 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 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.

  • How to find string range

    Say i have a string array from aa0 to aa100. Now how do i write a condition to check that this string lies between aa0 to aa100. please help

    This is the code what i have typed. Its working but when i enter a value which is less then 0 and greater than 99, it still works, where as it shouldnt. Please help
        public void focusLost(FocusEvent evt) {
                    if(evt.getSource() == mytextfield) {
                  System.out.println("Inside focuslost");
                  String text = mytextfield.getText();
                  if(text.startsWith("aa")) {
                       int value;
                       try {
                            value = Integer.parseInt(String.valueOf(text.charAt(text.length() - 1)));
                       }catch(NumberFormatException nfe) {JOptionPane.showMessageDialog(null,"textfield should be \n in the range of aa0 - aa99","Test",JOptionPane.ERROR_MESSAGE);return;}
                       if(value < 0 || value > 99) {
                            System.out.println("Inside if condition");
                            JOptionPane.showMessageDialog(null,"textfield should be \n in the range of aa0 - aa99","Test",JOptionPane.ERROR_MESSAGE);
                            mytextfield.transferFocus();
                            return;
                  else {
                        JOptionPane.showMessageDialog(null,"Invalid entry","Test",JOptionPane.ERROR_MESSAGE);
                        return;
        }

  • 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);
    }

  • How to check the source value is in between a string range in mapping

    Hi Consultants,
    I am working on IDOC to File scenario. I need to implement a specific requirement of our client. i.e. something like below;
    Vendor number can be any thing like 1AA000000 / 1AA000001/1AB000000/... ect till 1ZZ999999.
    if the vendor number is in between 1AA000000 -1ZZ999999 then the target value should assign as 'Internal' else should assing as 'External'.
    How to compare  that the value of vendor is in between IAA000000 to 1ZZ999999 in mapping?
    Appreciate your help.
    Thanks in advance.
    Regards,
    Nausheen

    You can try creating an UDF and using the varName.substring(); method. Then you can compare in separated pieces the string. For example
    String var = "1AA000000";
    if (var.substring(3).compareTo("000000") < 0 && var.substring(3).compareTo("999999") > 0)
      //compare now the "AA" and "ZZ" with the same logic;
    http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#substring(int, int)
    http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#compareTo(java.lang.Object)
    EDIT: Moreover, those functions are available in the Mapping program creation, but this should give a clue on the order it should be done.
    Edited by: Lucas Santos on Mar 29, 2011 7:38 PM
    Edited by: Lucas Santos on Mar 29, 2011 7:53 PM

  • 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);
    }

  • 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.

  • Range of strings as a case element is not inclusive

    I was using the following bit of code to translate some string characters into a Base36 but I discovered that the case element with a string range is not inclusive.  For example the following code executes the default case for a "Z" character.  Why is the string range element "A".."Z" not inclusive of its last element but a numeric range 1..10 would be?  Is this a bug?
    Solved!
    Go to Solution.
    Attachments:
    String Range in Case.png ‏12 KB

    Darin.K wrote:
    Perhaps you should post this little tidbit to the micro-nugget thread.
    Certainly! Another thread is LabVIEW Minutiae (that may bite you someday), which specifically focuses on potential "gotchas" such as this.
    a.lia-user-name-link[href="/t5/user/viewprofilepage/user-id/88938"] {color: black;} a.lia-user-name-link[href="/t5/user/viewprofilepage/user-id/88938"]:after {content: '';} .jrd-sig {height: 80px; overflow: visible;} .jrd-sig-deploy {float:left; opacity:0.2;} .jrd-sig-img {float:right; opacity:0.2;} .jrd-sig-img:hover {opacity:0.8;} .jrd-sig-deploy:hover {opacity:0.8;}

  • 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?

  • 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      
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • 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));

Maybe you are looking for