Menu

How to replace first , but not second , ?

2008-02-23
2012-11-13
  • Nobody/Anonymous

    Hi and big thumbs up for a great editor.

    I am trying to clean up a synonymous textfile that I have.
    So I would like to know if it's possible to do a replace function to change the first comma sign on each line to | or something else and not change the following commas on that line. But jump to next line and do a new replace.

    The current file is based like this:
    word1,synonym1,synonym 2,syn o nym3
    word2,synonym1,synonym 2,syn o nym3

    And I would like to become like this.

    word1|synonym1,synonym 2,syn o nym3
    word2|synonym1,synonym 2,syn o nym3

    If not but possible, then I would be happy to hear other solutions.

    Thanks in advance.

    TomYam
    Thailand

     
    • Nobody/Anonymous

      Thanks alot for your help.

      Tough it was not as straightforward as I thought.
      Needed to use the check-box of "regular expression".

      Then it worked like a charm. :-)

      As for "1 per line", tried to look for a setting for it, but I seem to be a little blind, as I have not found it.

      But big thanks for this help..

      TomYam..

       
      • Nobody/Anonymous

        The 1 per line checkbox is in the CTRL+R advanced Find/Replace dialog, which I almost use for anything to replace. It has a lot more checkboxes (including regex) than the regular CTRL+F Find dialog.

         
    • Nobody/Anonymous

      Did you tried the option "1 per line"?

       
      • Nobody/Anonymous

        Of course, this works for the first occurrence on a line. If you want to replace the second... You can use regular expressions to do so.

        Find field:
        ^([^,]+,[^,]+),

        Replace field:
        \1|

        This will match anything up to and including the second comma, re-placing the text before it and replacing the comma itself by the pipe character.

        For the first occurrence this is also possible:

        Find field:
        ^([^,]+),

        Replace field:
        \1|

        You may guess how this could be explained or described.