Search and Replace String throwing the wrong error message with regexp?

This came up in a LAVA thread, and I'm not sure if there's a bug here or not. When using Search and Replace string, and using a regular expression of [(G[b|i])], LabVIEW throws error -4622, "There is an unmatched parenthesis in a regular expression."  There are obviously no unmatched parenthesis in that expression, so it seems to me that the wrong error is being thrown. I'm just not sure if that's a syntactically valid regexp. The problem seems to be with nesting [ ]'s inside ( )'s inside [ ]'s. I've tried a couple of regexp resources on the Web, and one suggests it's valid, while the other seems to think it isn't.
Message Edited by eaolson on 03-13-2007 10:33 AM
Attachments:
ATML_StandardUnit2.vi ‏10 KB
regexp.png ‏5 KB

adambrewster wrote:
I think your regexp is invalid.
In regexps, brackets are not the same as parentheses.  Parens are for grouping, while brackets are for matching one of a class of characters.  Brackets can not be nested.
If the regexp is replaced with [G[bi]], there is no error, so it's not a matter of nested brackets. I couldn't find anything on the PCRE man page that forbids nested brackets specifically, but it makes sense.
Your expression "[(G[bi])]", therefore parses as a character class which matches '(', 'G', '[', 'b', or 'i' followed by an unmatched paren, and an unmatched bracket.
I don't believe that's the case. Replace the regexp with [(Gbi)], and the error goes away. So it's not a matter of the '(' being literal, and then encountering a ')' without a matching '('.
daveTW wrote:
what string exactly you want to replace? I think the round braces are not right in this case, since they mark partial matches which are given back by "match regular expression". But you don't want to extract parts of the string, you want to replace them (or delete, with empty <replace string>). So if you leave the outer [( ... )] then your RegEx means all strings with either "Gb" or "Gi".
It's not my regular expression. A poster at LAVA was having problems with one of his (a truly frightening one), and this seemed to be the element that was causing the problem. I'm pretty sure that the originator of the regexp meant to use G(b|i), which seems like a complicated way of matching "Gb" or "Gi", if you ask me.

Similar Messages

  • Search and replace string function

    Hello, I am using the "search and replace string" function and it does nt seem to work consistently for me.   I am using it in a situation where I am taking an array of strings, converting this into a spreadsheet string then deleting all of the commas.  Has anyone experienced the same behavior? I have searched through other posts and found other simular faults but none of the fixes worked for this. I can post the code it needed.
    Thanks,
    Andrew

    I agree that commas are often not desirable, especially if your software should also work in countries where comma is used as a decimal seperator.
    Where are the commas coming from? Does (1) each element of the original array have one (or more), do you (2) use comma as seperator if you convert it to a spreadhseet string?
    For (1), you might just strip out the comma for each element right in the loop. For case (2) you would simply use a different separator to begin with, of course.
    Btw: you are abusing a WHILE loop as a FOR loop, because you have a fixed number of iterations. Please replace it with a FOR loop. If you use a FOR loop, LabVIEW can manage memory much more efficiently, because it can allocate the entire output array before the loop starts. For While loops, the total number of iterations is not known to the compiler. (Of course a real program would also stop the loop if an error occurs. In this case you would need to stay woth the WHILE loop. )
    Do you have a simple example how the raw array elements look like. How many commas are there?
    LabVIEW Champion . Do more with less code and in less time .

  • Search and replace strings in a file while ignoring substrings

    Hi:
    I have a java program that searches and replaces strings in a file. It makes a new copy of the file, searches for a string in the copy, replaces the string and renames the new copy to the original file, thereafter deleting the copy.
    Now searching for "abcd", for eg works fine, but searching for "Topabcd" and replacing it doesnot work because there is a match for "abcd" in a different search scenario. How can I modify the code such that if "abcd" is already searched and replaced then it should not be searched for again or rather search for "abcd" as entire string and not if its a substring of another string.
    In the below code output, all instances of "abcd" and the ones of "Topabcd" are replaced by ABCDEFG and TopABCDEF respectively, whereas according to the desired output, "abcd" should be replaced by ABCDEFG and "Topabcd" should be replaced by REPLACEMEFIRST.
    try
              String find_productstring = "abcd";
              String replacement_productstring = "ABCDEFG";
              compsXml = new FileReader(compsLoc);
              compsConfigFile = new BufferedReader(compsXml);
              File compsFile =new File("file.xml");
              File compsNewFile =new File("file1.xml");
              BufferedWriter out =new BufferedWriter(new FileWriter("file1.xml"));
              while ((compsLine = compsConfigFile.readLine()) != null)
                    new_compsLine =compsLine.replaceFirst(find_productstring, replacement_productstring);
                    out.write(new_compsLine);
                    out.write("\n");
                out.close();
                compsConfigFile.close();
                compsFile.delete();
                compsNewFile.renameTo(compsFile);
            catch (IOException e)
            //since "Topabcd" contains "abcd", which is the search above and hence the string "Topabcd" is not replaced correctly
             try
                   String find_producttopstring = "Topabcd";
                   String replacement_producttopstring = "REPLACEMEFIRST";
                   compsXml = new FileReader(compsLoc);
                   compsConfigFile = new BufferedReader(compsXml);
                   File compsFile =new File("file.xml");
                   File compsNewFile =new File("file1.xml");
                   BufferedWriter out =new BufferedWriter(new FileWriter("file1.xml"));
                   while ((compsLine = compsConfigFile.readLine()) != null)
                         new_compsLine =compsLine.replaceFirst(find_producttopstring, replacement_producttopstring);
                         out.write(new_compsLine);
                         out.write("\n");
                     out.close();
                     compsConfigFile.close();
                     compsFile.delete();
                     compsNewFile.renameTo(compsFile);
                 catch (IOException e)
            }Thanks a lot!

    Hi:
    I have a java program that searches and replaces
    strings in a file. It makes a new copy of the file,
    searches for a string in the copy, replaces the
    string and renames the new copy to the original file,
    thereafter deleting the copy.
    Now searching for "abcd", for eg works fine, but
    searching for "Topabcd" and replacing it doesnot work
    because there is a match for "abcd" in a different
    search scenario. How can I modify the code such that
    if "abcd" is already searched and replaced then it
    should not be searched for again or rather search for
    "abcd" as entire string and not if its a substring of
    another string.
    In the below code output, all instances of "abcd" and
    the ones of "Topabcd" are replaced by ABCDEFG and
    TopABCDEF respectively, whereas according to the
    desired output, "abcd" should be replaced by ABCDEFG
    and "Topabcd" should be replaced by REPLACEMEFIRST.
    try
    String find_productstring = "abcd";
    String replacement_productstring = "ABCDEFG";
    compsXml = new FileReader(compsLoc);
    compsConfigFile = new
    BufferedReader(compsXml);
    File compsFile =new File("file.xml");
    File compsNewFile =new File("file1.xml");
    BufferedWriter out =new BufferedWriter(new
    FileWriter("file1.xml"));
    while ((compsLine =
    compsConfigFile.readLine()) != null)
    new_compsLine
    =compsLine.replaceFirst(find_productstring,
    replacement_productstring);
    out.write(new_compsLine);
    out.write("\n");
    out.close();
    compsConfigFile.close();
    compsFile.delete();
    compsNewFile.renameTo(compsFile);
    catch (IOException e)
    //since "Topabcd" contains "abcd", which is
    the search above and hence the string "Topabcd" is
    not replaced correctly
    try
                   String find_producttopstring = "Topabcd";
    String replacement_producttopstring =
    topstring = "REPLACEMEFIRST";
                   compsXml = new FileReader(compsLoc);
    compsConfigFile = new
    gFile = new BufferedReader(compsXml);
                   File compsFile =new File("file.xml");
                   File compsNewFile =new File("file1.xml");
    BufferedWriter out =new BufferedWriter(new
    dWriter(new FileWriter("file1.xml"));
    while ((compsLine =
    compsLine = compsConfigFile.readLine()) != null)
    new_compsLine
    new_compsLine
    =compsLine.replaceFirst(find_producttopstring,
    replacement_producttopstring);
    out.write(new_compsLine);
    out.write("\n");
    out.close();
    compsConfigFile.close();
    compsFile.delete();
    compsNewFile.renameTo(compsFile);
                 catch (IOException e)
    Thanks a lot!I tried the matches(...) method but it doesnt seem to work.
    while ((compsLine = compsConfigFile.readLine()) != null)
    if(compsLine.matches(find_productstring))
         System.out.println("Exact match is found for abcd");
         new_compsLine =compsLine.replaceFirst(find_productstring, replacement_productstring);
    out.write(new_compsLine);
    out.write("\n");
         else
         System.out.println("Exact match is not found for abcd");
         out.write(compsLine);
         out.write("\n");

  • Search and replace string formatting

    Hi,
    I am trying to do a search and replace formatting of a string.
    In the example I am looking for string "PASSED" but it must also start with usbflash and some number + PASSED.
    I can't get the format to have a number from 1-99. The number of replacements should add up to 6 in this case. I have tried with \d for any number, and I also tried [1-99].
    Solved!
    Go to Solution.

    Right click on the Search And Replace String function.  There is an option to use Regular Expressions.  Then give this a try.
    EDIT: You will need to set the Replace All input to TRUE.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Match Pattern.png ‏12 KB

  • Search and replace string problems

    Hi to all,
    I have problem with Search and replace string function. It shows me a wrong Value (Number) from 15 to 100 is everything OK (15=0, 30=1, 45=2, 100=3), but after 100 ........
    Take look in VI and if you have any ideas post them please
    THX
    Igor 
    Attachments:
    indexing.vi ‏10 KB

    there will be no 15115 string, but 15 or 115 and 15 is 0, 115 is 4. Anyway, i have changed string input format and now its working THX for your help
    Attachments:
    indexing.vi ‏10 KB

  • I am running Windows 7  and trying to update to iTunes version 10.5 (from version 10.3.1.55) and I keep getting the following error message, 'Error occurred while installing the updates. If the problem persists, choose Tools Download Only and try instal

    I am running Windows 7 home edition and trying to update to iTunes version 10.5 (from version 10.3.1.55) and I keep getting the following error message, ‘Error occurred while installing the updates. If the problem persists, choose Tools > Download Only and try installing manually’ which I do only to have the same error message pop up.

    Try updating your iTunes using an iTunesSetup.exe (or iTunes64Setup.exe) installer file downloaded from the Apple website:
    http://www.apple.com/itunes/download/

  • I've tried to install flash player several different times ans each time i get a connection error message.It downloads fine and when i run the file to start install,it installs up to 5% and then i get the connection error message.Can someone please help m

    I've tried to download the flash player several different times and each time i get a connection error message.It downloads fine and when i run the file to start install, it installs up to 5% and then i get the connection error message. I've tried disabling my antivirus software, closing my browser for install and nothing.Can someone please help me? I'm using Firefox.

    Hi!
    I had the exact same issue, being on a mac. If you are on a mac and the connection error message occurs, then use this link http://fpdownload.macromedia.com/pub/flashplayer/latest/help/install_flash_player_osx.dmg
    It allows you to download it offline, which is what I used.
    Hope I was help!
    -Haroon

  • I cannot run itunes, I keep getting this error message" Quick Time failed to initialized (error02096) Quick time is required to run please unistall itunes then install itunes again, I have done this three time and I keep getting the same error message.

    On my PC, I cannot run itunes, I keep getting this error message" Quick Time failed to initialized (error02096) Quick time is required to run please unistall itunes then install itunes again, I have done this three times and I keep getting the same error message. I have had itunes for years, but up until 2 months ago the quick time will not initialize to run it.

    Try using the Windows Installer Cleanup Utility and delete the iTunes installer. Then try installing iTunes again
    http://majorgeeks.com/Windows_Installer_CleanUp_Utility_d4459.html

  • I am having an installation failure issue with my itunes 11 software.  File is corrupted and i don't know what to do.  I've un-install and re-installed the software three times and continue to get the same error message.  It states that "This copy of ITun

    I am having an installation failure issue with my itunes 11 software.  File is corrupted and i don't know what to do.  I've un-install and re-installed the software three times and continue to get the same error message.  It states that "This copy of ITunes is corrupted or is not installed correctly.  Please reinstall Itunes"
    iMac, iOS 6

    HI,
    If your old version of iTunes is still working - then I sugest you stick with that.
    iTunes 11 is a lousy update - It will not retain your playlists, you can't find and delete duplicates... and a whole arry of oyher issues. (have a look around this forum to see how many issues IT11 gives people)
    Just a friendly advise and warning :-)

  • CS6 keeps crashing and I'm getting the following error message

    CS6 keeps crashing and I'm getting the following error message
    Problem signature:
      Problem Event Name:    APPCRASH
      Application Name:    Photoshop.exe
      Application Version:    13.0.1.0
      Application Timestamp:    5022da9d
      Fault Module Name:    image_runtime.dll
      Fault Module Version:    3.0.0.1
      Fault Module Timestamp:    5022d44f
      Exception Code:    c0000005
      Exception Offset:    000000000000e164
      OS Version:    6.1.7601.2.1.0.256.48
      Locale ID:    1033
      Additional Information 1:    a887
      Additional Information 2:    a88763af120bd826f987133067e96ba6
      Additional Information 3:    3d10
      Additional Information 4:    3d10b7e37b05a8ad1931741a7d65d6a3

    Useless without some system information.
    Mylenium

  • Using a variable in a Powershell search and replace string

    Hi
    a couple of days ago I posted a question about doing a search and replace with wildcards
    Search and repalce with Widcards
    I got a swift and very helpful answer but now I need to build on it.
    In a text file I wanted to replace all the text between two defined words.  the script I got was this
    $text = 'Some Server this bit of text varies Language stuff'
    $text -replace '(.*Server) .+? (Language.*)','$1 it will always say this $2'
    It works great but now I want to replace "it will always say this" with a variable and I can't figure out the correct grammar to make this happen.
    Can anyone help??
    Thanks
    Alex

    Here's one way:
    $replace = 'it will aways say this'if ( $text -match '(.*Server) .+? (Language.*)' )
    { "{0} $Replace {1}" -f $matches[1,2] }
    else { $text }
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • How to get numeric result from 'search and replace' string function

    hii
    i am using search and replace function to get output.my output is of form ' *X0123.3 ' .here i am replacing the term *X01 with space because i need only 23.3 as a result.but i am unable to get that out in the output indicator.i used lot of functions like string to number and so on but i am getting output as zero .can you please suggest me wt to do.i am attaching a copy of my file.
    Attachments:
    Untitled 1.vi ‏25 KB

    Your problem is the fact that you are converting it to an integer, thus loosing the fractional part. You need to use "Fract/Exp String To Number" instead and create a DBL so yor data is 23.3 instead of 23.
    You also don't need to manipulate the string if the initial part is of constant lenght. Just use the offset input as in the figure below.
    Message Edited by altenbach on 07-31-2006 07:02 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ToDBL.png ‏2 KB

  • TS4424 i have reinstalled both updates as advised above, but mail v4.6 still does not work and I still get the same error message on mail 4.5

    I have reinstalled both updates as advised above but mail v4.6 still does not work and mail v4.5 continues to have the same error message?

    Maybe some help here.
    http://support.apple.com/kb/TS4424

  • Match case in search and replace string

    Hi !
    Attached, my problem.
    I am searching "toto" in input string "toto+tototi" and replace "toto" by "A0".
    I want to "match case" the search input in order to get a string result : A0+tototi
    Does it exist options allowing to match case ?
    BR,
    Vincent
    Solved!
    Go to Solution.
    Attachments:
    MatchCase.vi ‏8 KB

    Please fill all your controls with typical strings, make the new values the default, save the VI under a new name, and attach it again.
    (This allows us to quickly reproduce your problem without entering strings and having to guess what your inputs actually are)
    WIth your given string, the result seems as expected, so we need more information on what you actually want instead.
    LabVIEW Champion . Do more with less code and in less time .

  • Search and Replace values in the text field before values are stored to DB

    Hi,
    In my application there is a question - text area and answer - text field. Problem is, some answers are stored with the single quotes to the DB and I have a problem while retrieving it from the DB. I need to replace the 1 single quotes with 2 single quotes. The values are stored to the DB when the submit button is clicked.
    So I am using the following javascript code:
    italics
    <script type="text/javascript">
    function test()
    var str="&P2_S1.";
    document.write(escape(str));
    </script>
    italics
    I need to call this javascript function, when the submit button is clicked but BEFORE the values are stored to the DB. How can i get this done?
    Please let me know.

    Hi,
    Thanks for the reply.
    Yeah I planned to drop the Javascript idea.
    Now, I am using the PL/SQL code. This is what I am planning to do.
    When the user enters any word like this, Test's, this single quote should be replaced by some special character, #@@#, - what is the PL/SQL code for this?
    Right now my PL/SQL code is:
    begin
    update test set S1=:P2_S1 where name=:APP_USER;
    end;
    so the replacing part should come somewhere before the update statement.... how can I do it?
    from the DB when the values are retrieved, I use the following code:
    select REPLACE(s1,'''','') from test where NAME=:APP_USER; // this works fine.
    Please help me with the replace of the single quote before the update process...

Maybe you are looking for