Community
    • Login

    rereplace help

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 2 Posters 128 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • TreyT
      Trey
      last edited by

      I’m trying to automate some of my coding tasks using pythonscript and running into an issue I think regex should be able to solve. I want to replace things that are specifically surrounded by certain characters while preserving the middle part.

      so for example:

      " & Placeholder &"

      becomes:

      {Placeholder}

      I thought that named capture variables would be able to do this but I am getting an empty {} trying to use them in this situation with the code:

      editor.rereplace(r" & \b(?<Placeholder_Variable>[a-zA-Z0-9._]*)\b & “,r”{(?{Placeholder_Variable})}")

      Alan KilbornA 1 Reply Last reply Reply Quote 1
      • Alan KilbornA
        Alan Kilborn @Trey
        last edited by Alan Kilborn

        @Trey

        You have several things wrong in your regular expression.

        Try this instead:

        editor.rereplace(r'" & (?<Placeholder_Variable>\w+) &"', r'{$+{Placeholder_Variable}}')

        EDIT: Oops, the first version of this posting used Python named capture group stuff; I’ve adjusted to use Boost equivalents.

        TreyT 1 Reply Last reply Reply Quote 3
        • TreyT
          Trey @Alan Kilborn
          last edited by

          @Alan-Kilborn I had to re-add ‘.*’ to the middle section, but I got it working now and can use variables the way I want now, thanks!!

          1 Reply Last reply Reply Quote 2
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors