Menu

Reg Exp possible bug

2007-11-26
2012-11-13
  • Hashim Kubba

    Hashim Kubba - 2007-11-26

    lets say i have a large SQL file with this kind of inputs:
    insert into ROLE_MODULE(ROLE_ID,MODULE_ID) values(1376,15);
    insert into ROLE_MODULE(ROLE_ID,MODULE_ID) values(1502,15);
    ...
    insert into ROLE_MODULE(ROLE_ID,MODULE_ID) values(1386,16);
    insert into ROLE_MODULE(ROLE_ID,MODULE_ID) values(1582,16);

    I want to modify all the module_id=15 lines using Reg. Exp.
    I used
    insert into ROLE_MODULE\(ROLE_ID,MODULE_ID\) values\(\d+,15
    it worked in http://jakarta.apache.org/oro/demo.html

    yet it is not working in NotePad++
    I can find
    insert into ROLE_MODULE\(ROLE_ID,MODULE_ID\) values\(\d+
    but if i add the last comma, it simply say can not find the string

    any ideas

     
    • Nobody/Anonymous

      I think it is the \d which is not working. Try [0-9] instead.

       
      • Nobody/Anonymous

        It seems \d is also working. I have no problem using the complete reg ex. It finds the two matches in your example.

         
        • Nobody/Anonymous

          could you be (unintentionally) trying to match a comma to a semicolin?

           
    • Hashim Kubba

      Hashim Kubba - 2007-11-27

      Ok try this one
      insert into ROLE_MODULE(ROLE_ID,MODULE_ID,ACCESS_TYPE_CODE) values(1536,17,'2'); -- Role:
      insert into ROLE_MODULE(ROLE_ID,MODULE_ID,ACCESS_TYPE_CODE) values(1427,17,'0'); -- Role:
      insert into ROLE_MODULE(ROLE_ID,MODULE_ID,ACCESS_TYPE_CODE) values(1597,17,'0'); -- Role:

      search with
      insert into ROLE_MODULE\(ROLE_ID,MODULE_ID,ACCESS_TYPE_CODE\) values\([0-9]+,

      without the last comma it will work
      with it will not?

       
      • Nobody/Anonymous

        You freak! You wanna prove me wrong?! ... You succeeded...

        This one doesn't work for me either. It seems the line is just too long. If you remove some of the front characters, you can expand the regex with the , and possibly the 1(7).

        I think you can work around this by performing a (regex) replacement twice.
        If you first replace the specific part and most of the preceding text by a simple unique identifier/marker or text, you can perform a standard replace of this text (no regex needed to find it) in the next pass.

         
        • Nobody/Anonymous

          As an alternative to do it all in one pass, you may use a regex for the fixed part of the string, too. Try this:

          ^insert [^P]+PE_CODE\) values\([0-9]+,

          It uses the characteristic character P to find the specified string, so by itself the complete regex is shorter. I guess there is enough "room" now to extend the regex by the desired number.