Menu

Find parenthetical string

2008-03-19
2012-11-13
  • Nobody/Anonymous

    I'm having trouble finding strings that begin and end with parentheses. For example, I want to be able to find:

    {at12345}
    (at12345(
    }at12345}
    }st12345{

    where "12345" is a string of 2 to 5 numerical characters.

    I want to replace the string with "@".

    Thanks.

     
    • Nobody/Anonymous

      regular expression match
      ([{}()])[a-z][a-z][0-9][0-9][0-9][0-9][0-9]([{}()])

      replace with
      \1@\2

      and then modify and repeat for 2, 3, and four digits instead of five

       
    • Nobody/Anonymous

      Thanks! I apologize for inadvertently using curly brackets where I should have indicated parentheses. The four variations should have been:

      (at12345)
      (at12345(
      )at12345(
      )at12345)

      The "at" is a constant. The number of numerals varies from two to five.

      I modified your instructions as follows

      ([()])at[0-9][0-9][0-9][0-9]([()])

      which gets replaced with @

      Thanks again for pointing me in the right direction.

      Now I have to figure out how to add a comma at the end of each line. Using $ works but, for some reason, skips every other line. I'll post a new topic if I can't figure it out.

       
      • Nobody/Anonymous

        Find:
        ([()])at(\d+[()])

        Replace:
        \1@\2

        Replaces the at followed by any number of digits.

         
      • Nobody/Anonymous

        Take a look at these similar messages, if you didn't already:

        "how to append lines with a comma or other characters"
        http://sourceforge.net/forum/message.php?msg_id=4833798

        Are you trying to replace the at=@ and appending the comma at the same time?

        Or do you have different linebreaks in your document?