Community
    • 登入

    How to remove part of a phrase multiple times

    已排程 已置頂 已鎖定 已移動 General Discussion
    5 貼文 4 Posters 304 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • Martina MizziM
      Martina Mizzi
      最後由 編輯

      I am trying to remove the part of the phrase
      “GridLink data-title=spaceship data-category-name=“space game” data-widget-event=videogame>”

      from this phrase:

      data-testid=SpaceshipGridLink data-title=spaceship data-category-name=“space game” data-widget-event=videogame>

      From multiple sentences… these all begin with gridlink and end with videogame>

      how do i go about this please? Many thanks!

      1 條回覆 最後回覆 回覆 引用 0
      • guy038G
        guy038
        最後由 guy038 編輯

        Hello, @martina-mizzi and All,

        Not difficult with regular expressions ! So :

        • Open your file with N++

        • Open the Replace dialog ( Ctrl + H )

          • SEARCH (?-si)GridLink.*?videogame>

          • REPLACE Leave EMPTY

          • Tick the Wrap around option

          • Select the Regular expression search mode

          • Click, once on the Replace All button or several times on the Replace button

        Et voilà !


        Notes :

        • The (?-si) part ensures that the search will be sensible to case and that the dot meta-character will match a single standard char, only ( Not EOL chars )

        • Then, the parts GridLink and videogame> looks for these literal strings

        • In between, the part .*? tries to match the shortest range of any standard char(s), even zero

        Best Regards,

        guy038

        1 條回覆 最後回覆 回覆 引用 2
        • Martina MizziM
          Martina Mizzi
          最後由 編輯

          Thanks so much guy!

          1 條回覆 最後回覆 回覆 引用 0
          • Anandkumar PrajapatiA
            Anandkumar Prajapati
            最後由 編輯

            Open your document in N++.
            Go to the start of the document by clicking on ctrl+home.
            Open The Replace Dialogue Box (ctrl+h).
            Enable Wrap around option.
            Under search, mode Select regular expression.
            Enable the .matches newline.
            write the following in the fields.
            Find what: (?s)(?i)(GridLink.*?videogame>)
            Replace with: leave this field blank.
            Click on Replace All.

            Description:
            (?s)enables dot matching newlines.
            (?i) makes match case insensitive.
            (GridLink) Literal string.
            (.*?) Matches shortest range of string.
            (videogame>) Literal string.

            PeterJonesP 1 條回覆 最後回覆 回覆 引用 0
            • PeterJonesP
              PeterJones @Anandkumar Prajapati
              最後由 PeterJones 編輯

              @Anandkumar-Prajapati ,

              I am curious what you were trying to accomplish with your post. It was nearly identical content to Guy’s post. The places where you varied from Guy’s were either inconsequential, or nearly so for the original data shown.

              If you have a unique point you were trying to make with your slight differences, I don’t know what that point was – so if it really is trying to make a point, please explain yourself more. It might be educational for the original poster or future readers to know why you made the choices you did – but only if you explain why.

              Otherwise, I want to point out that rephrasing advice that has already been given looks a lot like trying to take credit for someone else’s work – which is highly frowned upon (to say the least). I try to give the benefit of the doubt in such circumstances, so I am not saying that it was intentional; but it is a good idea to read the whole thread before posting, and to try to avoid giving the same advice without adding anything new, in an effort to avoid such appearances.

              1 條回覆 最後回覆 回覆 引用 0
              • 第一個貼文
                最後的貼文
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors