Community
    • Login

    Problem with Find and replace using Regex

    Scheduled Pinned Locked Moved General Discussion
    regexsearch & replace
    2 Posts 1 Posters 2.3k 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.
    • Noel WorlandN Offline
      Noel Worland
      last edited by

      Hi All,
      Please bear with me as I’m a total newbie to regex syntax.
      I have a text file which I’m trying to do a find and replace on using regex because normal find and replace would take too long. The text file is over 1 million lines long. My regex search successfully finds what I need. My replace successfully replaces it. But the problem is - after clicking “replace all” the text file is now over 2 million lines. I think it has something to do with the replace regex syntax
      Example of lines I’m searching for - model “AMURRY 150327 DR PIPE UG”

      My Regex find - model\s"(AMURRY|CKB|CLAYDEN|DARACON|DOWNER|FREDON|FULTON HOGAN|FH DWC|FUSION|GFIS|HUSKY|LEND LEASE|M AND P|MURPHY|OLYMPIC|ROBSON|SAFEGATE|SAGEGATE|SPANTECH|STOWE|WILKEN) \d+\s

      My regex replace - model "$`

      Can anyone tell me why it is adding all the extra lines. Or suggest a better way? Thanks in advance

      1 Reply Last reply Reply Quote 0
      • Noel WorlandN Offline
        Noel Worland
        last edited by

        Hi I found my own solution -
        My Regex find -
        (model\s"(AMURRY|CKB|CLAYDEN|DARACON|DOWNER|FREDON|FULTON HOGAN|FH DWC|FUSION|GFIS|HUSKY|LEND LEASE|M AND P|MURPHY|OLYMPIC|ROBSON|SAFEGATE|SAGEGATE|SPANTECH|STOWE|WILKEN) \d+\s)(.*)

        My regex replace - model "\3

        it now does not add the million lines of text.

        1 Reply Last reply Reply Quote 0

        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