How to remove part of a phrase multiple times



  • 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!



  • 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



  • Thanks so much guy!



  • 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.



  • @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.


Log in to reply