Regex excluding a certain string

Hi
I have a question about how to search the strings that are in between a "start" and an "end". The results should not contain the word " cat ". All the strings with the format "start xxxxx yyyy end" that do not contain the word " cat " are valid. That is, the string "start XXX cat YYYY BBB end" should be rejected.
I am using the regex "start(.*?)end" to find all the strings that start with "start" and ending with "end".
The expression [^cat] can be used to negate the characters "cat" in any sequence (atc,act...). I want only to negate the sequence "cat". Any ideas about how to exclude the strings with "cat"in an effective way???
Regards

When you want to exclude whole
sequences of characters, you have to use negative
lookahead:
  String regex =
"start\\s+((?!cat\\s+)\\S+\\s+)*?end";
How does this regex work and where the "next search starts" in case the match fails because the string " cat " was found.
We assume that there is a string "..startXXXVVVFF CC CAT xxx end......."
This regex searches for the string "start" (in position a). When it finds "start" it starts "looking ahead" for the occurrence of " cat " (position a + 10). The string "end" is in position a+20. That is, it will find the string " cat " before it finds "end". It will discard the match. After discarding the "match" where does the regex starts searching for a new "start"?
Does it start searching for a new match (sartXXXend)direct after the previous "start" (that is, at position a+1). Or does it starts searching after a new match after the previous "end" (at position a+21)????

Similar Messages

  • Read Text file and count occurences of certain string

    Hello,
    I have a text file with lines of data in it. I would like to read this text file and count how many lines match a certain string of text. 
    For example my text file has this data in it.
    dog,blue,big
    dog,red,small
    dog,blue,big
    cat,blue,big
    If the certain string of text is "dog,blue,big" then the count would return "2".
    Thanks for your help

    Hello,
    Thank you for your post.
    I am afraid that the issue is out of support range of VS General Question forum which mainly discusses the usage issue of Visual Studio IDE such as
    WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System
    and Visual Studio Editor.
    I am moving your question to the moderator forum ("Where is the forum for..?"). The owner of the forum will direct you to a right forum.
    In addition, if you are working with Windows Forms app. please consult on Windows Forms Forum:http://social.msdn.microsoft.com/Forums/windows/en-US/home?category=windowsforms
    If you are working with WPF app, please consult on WPF forum:
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wpf
    If you are working with ASP.NET Web Application, I suggest that you can consult your issue on ASP.NET forum:
    http://forums.asp.net/
     for better solution and support.
    Visual Studio Language Forums:
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=vslanguages
    Best regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Regex Pattern For this String ":=)"

    Hello All
    True, this isn't the place to ask this but here it is anyway, if you can help please do.
    Can anybody tell me the regex pattern for this String:
    ":=)"
    Thanks
    John

    Yep, cheers it's ":=\\)"
    public class Test {
         public static void main( String args[] ) {
              String s = "one:=)two:=)three:=)four";
              String ss[] = s.split( ":=\\)" );
              for( int i=0; i<ss.length; i++ )
                   System.out.println( "ss["+i+"] = {" + ss[i] + "}" );
    }resulting in:
    ss[0] = {one}
    ss[1] = {two}
    ss[2] = {three}
    ss[3] = {four}

  • Set color in TextArea for certain String

    I need to highlight some Strings in different color than the setForeground() in the TextArea. Is it possible and how can I accomplish it?
    Help is great appreciated.
    Anna

    I am able to use JTextPane to highlight certain string now.
    Thanks a lot.
    Though I am having problem on mouse double click on a file name.
    For TextArea, the getSelectedText() will pick the full path name of the file. For JTextPane, the selected text is just part of the string.
    Following is the text:
    Test report is saved in file C:\tests\pf2150\JTAG\888_test.rpt
    The file name is
    C:\tests\pf2150\JTAG\888_test.rpt
    My mouse is over the file name but double click only picks JTAG or pf2150 or ...
    Could anybody help?
    Anna

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

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

  • Regex backreference combined with string - how to separate

    Hi, 
    I'm doing a replace with a backreference but the backreference is being interpreted as part of the string instead. If I insert a space it is interpreted correctly but I do not want to have a space.
    Here's the code:
    $regex = '(<add key="Global.LoadBalancer.ServerFarmIPAddresses.CSV"\svalue=")(?:[^"]+)("\s/>)'
    $fillerString = '$1127.0.0.1$2'
    The expected result should be to change this string:
    <add key="Global.LoadBalancer.ServerFarmIPAddresses.CSV" value="10.10.10.10,10.10.10.9,10.128.128.211,10.128.128.111" /> 
    And change it to this one:
    <add key="Global.LoadBalancer.ServerFarmIPAddresses.CSV" value="127.0.0.1" /> 
    But instead it changes it to this:
        $1127.0.0.1" />    
    How can I separate the $1 from the Ip address without adding a space?

    Put curly braces around the "1" and "2" in the replacement string:
    $fillerString = '${1}127.0.0.1${2}'

  • Capture rule to exclude some certain user ids.

    Hi,
    We have tables that have a column that tells you which user id made the change for that record. We are requested to not to capture changes made by some certain user ids. Do you know if we can set some rule to do this?
    Thanks.

    Hi,
    Modify the streams rules to exclude changes made by certain user ids.
    You can use DBMS_STREAMS_ADM package to create a new rule and drop the existing rule.
    http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28419/d_streams_adm.htm
    Or alter the existing rule using DBMS_RULE_ADM.ALTER_RULE Procedure
    Regards
    Bilahari
    Edited by: Billu on Apr 15, 2009 5:47 PM

  • How to count occurences of a certain string in incoming real-time data? Also displaying RTC data. Current VI included

    I use LabView student Express 7 on a Windows XP system.
    Time-frame: we are doing final integrations for our balloon experiment today. We just got told that the press wants to view real-time data, which we haven't programmed for. I need help to get a working VI at the latest by 25.02.2004 before 0800(morning) (GMT+1).
    Note on license
    It is a student balloon flight, and the data will not be used in scientific work, so the I am not breaking any license agreements (I hope).
    Problem synopsis:
    The balloon continually transmits data at 9600baud. The data is a semi-repeating header followed by a constant lenght data-package arranged like this:
    BEXUS[h][m][s]BEXUS[h][m][s]
    [Raw binary data, 7channels*8sub-channels*8bits]
    What the groundstation is doing right now:
    Take all incomming data and save (append) the data to a file without any data-handling. (We figured we would go post-processing).
    What I need to change in less than 24 hours:
    - Add a "package" counter
    - Add a display of the clock data (RTC)
    How I planned to implement the changes:
    -RTC display:
    The RTC data is in BCD format, since that means that if you look at the data as hex numbers, you get the hours and minutes and seconds out in "clear text". That is 12 hours is 0x12hex. I figured that I can do a match pattern BEXUS and pass the "after substring" to another match pattern BEXUS from which I feed the "before substring" to a type-cast VI (casting string to u8) and displaying that, which should give me a display of "123000" for the time 12:30:00... I couldn't get it to work at all when I tried out the supplied "beta" vi.
    - Package counter:
    Counting how many BEXUS that gets detected and dividing by 2. I don't know how to do this. I've looked on the forum (a good thread on the problem: "how do I count the number of *'s in a string") but these use either loops or arrays... and I'm not sure how this works when I'm getting the data in at realtime. I cant make an array and then count it, since then the array would grow fast and possibly interfere with saving of the data??? Saving the data is critical.. without that file we cant do post-processing.
    Since my time is so limited (I'm not even supposed to do the groundstation software but they called on me in the last minute because no-one else had time/wanted too/could do it) I hope that you could make an exception and provide me with working VI's (based on the one I have attached) so that I can show something to the press! (Free comercial for NI!! Since the student version shows the National Instruments water-mark on all VI's!!! Possible TV time!!)
    Thanks!
    PS: even if you are to late (after 25) post anyway!
    Why:
    -I can learn from it
    -the launch might be delayed due to weather conditions
    -others might find it amusing!
    Thanks again!
    Attachments:
    BexusII_groundstation.vi ‏46 KB

    I have a valid example data file attached to this thread.
    If you open BEXTEST.bin in a hex-editor of your choice, you'll see the BEXUS as 42 45 58 55 53 and then the time as 00 28 09 etc.
    I couldn't get Joe Guo's VI to work. It doesn't count packages correctly, and the time is not displayed correctly either.
    The file was saved using a straight save to file VI.
    The data is from actual launching area tests performed a few mintues ago. The time displayed is "On time" e.g. how long the gondola has been powered up.
    I have a spare T-junction, so I can hook into the balloon real-time data as we fly, in case anyone care to see if they can figure out why the latest version of Joe Guo's program is not displaying correctly.
    I will monitor this
    thread during and after flight to see if anyone can make it in time!
    Thanks for the great effort!!
    Attachments:
    bextest.bin ‏53 KB

  • Search on a BLOB  and not finding certain STRINGS...

    I copied a search that Denes uses on his APEX How To Site (God I love that site) and customized it a little bit for my needs. Here's the interesting problem...
    if I have a string of text within the attachment like
    cgext.nfc_pacs1
    the search returns with no records found. But if I only use
    cgext.nfc
    then I get a slew of returns. Most of them with _pacs1 and some with other extensions...
    So I'm wondering, why is the search not finding the complete string that I enter into the search field when I've copied the string and pasted it into the field from a record that I know is in the Uploaded_Files table...
    Any ideas?
    First the Search:
    SELECT ID, score (1) relevance,
    SUBSTR (UPLOADED_FILE_NAME, INSTR (UPLOADED_FILE_NAME, '/') + 1) file_name
    FROM UPLOADED_FILES
    WHERE contains
    (blob_content,
    CASE
    WHEN :p500_search_on_blob IS NULL
    THEN 'this_text_doesnt_exist'
    ELSE '%'
    || :p500_search_on_blob
    || '%'
    END,
    1
    ) > 0
    Second, I made sure that I ran an index on UPLOADED_FILES
    Third, I made sure that I ran a DBMS stats on the table / blob_content...
    I'm at a loss as to why full text searches on strings that I know are on documents inside of the table are not finding them. Only when I cut down the search phrase does it kinda work...
    Message was edited by:
    mikedlong
    Message was edited by:
    mikedlong

    I think I know what is happenening but I'm not sure why it is happening...
    If I take the underscores out of the search then it will find the complete string, but why is this only happening with Underscores? Is there something that I'm missing with search logic that I should know?
    I ran another search on the BLOB with the following text string that I know should have found 1 record:
    CBS_USB_ACCOUNTING_LINES_TEMP
    It didn't... now when I ran the search string with CBS USB ACCOUNTING LINES TEMP it found the one record.
    I guess the problem is going to happen when I'm long gone from here and the person in my job is asked to run a search against cgext.po_t16_vendor_association and they forget to pull out the underscores...
    Again, thanks to anyone with some information on how (if I even can) I can get the search to work as a litteral search against the blob content...
    And thanks Denes... you've been credited on my work here in the application I'm building for the features you've taught me in your web page...
    Mike Long

  • Made a script to find share paths; How do I exclude with certain criteria

    I have a few file server clusters with a bunch of shares on them and I need to add permissions for a security group to all the shares. The first step is getting all the shares. I can do this with gwmi -class win32_share so I wrote a powershell script to
    do this across all the file servers. It works as expected with one issue, it gives me the share paths plus the path to the drive letters (i.e. \\FileServer\J$). I am thinking I can put some kind of IF statement to exclude anything with *$* but I don't know
    how to go about this. Any thoughts?
    Import-Module activedirectory
    $ErrorActionPreference = "SilentlyContinue"
    $ComputerName=Get-ADComputer -Filter {name -like "FS*"} | %{$_.dnshostName}
    $Computers=gwmi -class win32_share -computername $ComputerName
    ForEach ($Computer in $Computers){
    Write-Host $Computer.Name

    gwmi -class win32_share  -filter 'type=0 and name <> "print$"'
    This ignores all admin shares.
    ¯\_(ツ)_/¯

  • Searching for certain string with wildcards

    Hi all,
      I am trying to find the characters  'GW' in material description with these examples:
      A)     (GW51) Metal spec round   --normally written this way
       B)     GW51) Metal spec round  -- typing error omit the left brackett
       C)     (GW51  Metal Spec round  --  typing error  omit the right brackett
       The codes works for A and C.
           FIND FIRST  OCCURENCE OF '(GW'  in material_desc.
       I am unable to use wildcards to find for GW*)  for B using FIND statement.
      Can anyone share with me using FIND for B ? 
    Thank you.
    Joyce

    use CP.
    if material_desc CP '*GW*'.
      write material_desc. " or do what ever you want.
    endif.

  • Excluding a name string

    I am trying to produce a list of business names from a database. I don't want to include any churches so I am using the following code for the exception
    AND CUST_NM_TXT LIKE '%CHURCH%'
    but of course I am getting all kinds of iterations like churchill ,etc
    Is there a way to only select those names that contain a separate word "church" out the name ?

    This?
    AND UPPER(' '||CUST_NM_TXT||' ') LIKE '% CHURCH %'

  • I am a Tiger user, with a question about Leopard's smart folders!

    Hello!
    I starting toying with smart folders under Tiger. It is my understanding that smart folders under Leopard have some different/improved features.
    What I was wondering is, is there a way to EXCLUDE a certain string of alpha-numerics as a refining search parameter? I am looking to better sift through Logic Pro projects and it would be amazing if I could weed out any project that had ".0" in the project name (to weed out the backup projects while still finding showing the core Logic projects).
    It would be very helpful to know if this is possible before I finally make the plunge into Leopard. Also, knowing might dictate how I am overhauling the organization of my files right now, at this time. Thanks!

    wow that is weird. Because I know that in tiger, you can check box as many folders as you like to be included in the search. In leopard, i guess they want you to have one smart folder for every folder you want to search the contents of?
    Hopefully, people can get around that by just consolidating some of the folders (putting folders within folders) that they wanted to search through one smart folder.
    But anyway, that is great news about the option to EXCLUDE! Tiger's is definitely missing that. I searched for Name Extensions that are ".logic", but that also gets me tons and tons of project backups. Those backups all have a number, such as ".01" or ".02" interjected before the ".logic" extension. Excluding ".0" would hopefully not include a file such as this one "mysong.01.logic"
    Thanks for your help! I will look forward to this working in Leopard!

  • Problems with String.split(regex)

    Hi! I'm reading from a text file. I do it like this: i read lines in a loop, then I split each line into words, and in a for loop I process ale words. Heres the code:
    BufferedReader reader = new BufferedReader(new FileReader(file));
    String line;
    while ((line = reader.readLine()) != null) {
        String[] tokens = line.split(delimiters);
        for (String key : tokens) {
    doSthToToken();
    reader.close();The problem is that if it reads an empty line, such as where is only an "\n", the tokens table has the length == 1, and it processes a string == "". I think the problem is that my regex delimiters is wrong:
    String delimiters = "\\p{Space}|\\p{Punct}";
    Could anybody tell me what to do?

    Ok, so what do you suggest?I suggest you don't worry about it.
    Or if you are worried then you need to test the two different solutions and do some timings yourself.
    And how do you know the regex lib is so slow and badly written?First of all slowness is all relative. If something takes 1 millisecond vs 4 milliseconds is the user going to notice? Of course not which is why you are wasting your time trying to optimize an equals() method.
    A general rule is that any code that is written to be extremely flexible will also be slower than any code that is written for a specific function. Regex are used for complex pattern matching. StringTokenizer was written specifically to split a string based on given delimiters. I must admit I haven't tested both in your exact scenario, but I have tested it in other simple scenarios which is where I got my number.
    By the way I was able to write my own "SimpleTokenizer" which was about 30% faster than the StringTokenizer because I was able to make some assumptions. For example I only allowed a single delimiter to be specified vs multiple delimiter handled by the StringTokenizer. Therefore my code could be very specific and efficient. Now think about the code for a complex Regex and how general it must be.

Maybe you are looking for

  • Signal Express 2009 causing NIMAX to generate an Error Exception message

    I have a system that gives an error message when I try to open an instrument in NIMAX. The popup error message says "unexpected Error", with a code of "MAXKnownException. This system is running Windows XP and we had Signal Express 3.0 with NIMAX 4.3

  • Management Center for CSA v.6.0

    Help me please to solve the problem. I had installed Management Center for Cisco Security Agent v.6.0. However I can't generate Agent kit. The status of all Agent kit is "Needs rule generation". I try to generate rules but there is an error - Failed

  • Udo form matrix binding

    Hi, I created one UDO form. in that i am trying to fill the matrix with recordset. becoz i am selecting the value from combobox and i run the query with this value. so this resultant record set i want to fill in matrix rows. oForm = SBO_Application.F

  • Why is Brdge not included in Lightroom 4?

    Lightroom needs a browser to work efficiently and Bridge should be a part of the program.  If I open the Photoshop Bridge, it automatically opens Photoshop every few minutes and I have to take the time to watch it open and wait for it to close.  The

  • Bloquer le clik de la souris un certain temps

    Bonjour,  j'ai actuellement une application qui est assez importante. En effet, j'utilise une commande a onglet, lorsque je suis au dernier onglet et que mon programme est fini l'application garde cette dernière vue sur ce même derneir onglet. Le pro