Community
    • Login

    rereplace help

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 2 Posters 862 Views 1 Watching
    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 Offline
      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 Offline
        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 Offline
          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

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors