Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    RegEX in Notepad++ removing different text with \ in it

    Help wanted · · · – – – · · ·
    3
    4
    129
    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.
    • Magnum Opus
      Magnum Opus last edited by

      If I have a list of text in Notepad++ and I want to replace like this

      C:\thingie\things\test3\merchant\test\test_
      C:\thingie\notthings\test3\merchant\test\test_
      C:\thingie\thesethings\test5\merchantweird\test\test_
      C:\thingie\thosethings\test5\merchant\test\test_
      C:\thingie\anythings\test3\police\test\test_
      C:\thingie\notsothings\tesrret3\merchant2\test\test_
      C:\thingie\things\test_

      Which needs to be replaced into

      Newtext=otherplace(test=test_

      with the only thing retained is the test_ from the previous list.

      I have it somewhat working, but I can’t get it to do * and \ together.

      So what would be the correct RegEX in Notepad++ to replace this way?

      1 Reply Last reply Reply Quote 0
      • PeterJones
        PeterJones last edited by

        @Magnum-Opus ,

        I have it somewhat working, but I can’t get it to do * and \ together.

        So show us what regex you’ve tried, and show us the results, explaining why it doesn’t match what you wanted. Otherwise, you’re asking us to start from scratch, rather than knowing what you tried and using that as a starting point.

        Also, please properly markup your post, so that we see the exact data, rather than letting the forum mangle your data for you (see the FYI below). Given the backslashes and asterisks in your post, it is highly likely that what we see no longer accurately reflects your data; when you preview your post, you can see what we will see, so you will know whether the forum will mangle things or not. If you properly markup (using the syntax in the links below, or using the formatting bar), then we will be more confident that we accurately see your data.

        Please read the following:

        -----
        FYI:

        This forum is formatted using Markdown, with a help link buried on the little grey ? in the COMPOSE window/pane when writing your post. In the new-and-improved forum, there is the nice </> button, which automatically marks up the text as code (so that the forum won’t mangle your example text), and you can imbed images using the little image button. If you want to do manual markdown in your post, please see @Scott-Sumner’s post in the “how to markdown code on this forum” topic, and my updates near the end. It is very important that you use these formatting tips – using single backtick marks around small snippets, and using code-quoting for pasting multiple lines from your example data files – because otherwise, the forum will change normal quotes ("") to curly “smart” quotes (“”), will change hyphens to dashes, will sometimes hide asterisks (or if your text is c:\folder\*.txt, it will show up as c:\folder*.txt, missing the backslash). If you want to clearly communicate your text data to us, you need to properly format it.

        If you have further search-and-replace (“matching”, “marking”, “bookmarking”, regular expression, “regex”) needs, study this FAQ and the documentation it points to. Before asking a new regex question, understand that for future requests, many of us will expect you to show what data you have (exactly), what data you want (exactly), what regex you already tried (to show that you’re showing effort), why you thought that regex would work (to prove it wasn’t just something randomly typed), and what data you’re getting with an explanation of why that result is wrong. When you show that effort, you’ll see us bend over backward to get things working for you. If you need help formatting, see the paragraph above.

        Please note that for all regex and related queries, it is best if you are explicit about what needs to match, and what shouldn’t match, and have multiple examples of both in your example dataset. Often, what shouldn’t match helps define the regular expression as much or more than what should match.

        1 Reply Last reply Reply Quote 3
        • Magnum Opus
          Magnum Opus last edited by Magnum Opus

          C:\Ark\Servers\EOGamer2.0-PvP-Ragnarok\ShooterGame\Content\Mods\731604991\doors\gates\small\glass\EngramEntry_
          C:\Ark\Servers\EOGamer2.0-PvP-Ragnarok\ShooterGame\Content\Mods\812655342\structures\fertilizersilo\EngramEntry_
          D:\Backup\Ark\Mods\84729343\EngramEntry_
          

          in fact ANY text before and including

          \EngramEntry_
          

          is to be replaced to this

          OverrideNamedEngramEntries=(EngramClassName="EngramEntry_
          OverrideNamedEngramEntries=(EngramClassName="EngramEntry_
          OverrideNamedEngramEntries=(EngramClassName="EngramEntry_
          

          This works, but is not what I want

          \\EngramEntry_
          

          But

          *\\EngramEntry_
          

          doesn’t and doesn’t select anything

          _I am completely at a loss on how to do this with RegEX. The documentation isn’t very clear on how to proceed with this.

          dinkumoil 1 Reply Last reply Reply Quote 2
          • dinkumoil
            dinkumoil @Magnum Opus last edited by dinkumoil

            @Magnum-Opus

            Your search term *\\EngramEntry_ doesn’t work because you used the quantifier * without a preceeding character to define the character(s) the quantifier should operate on.

            Because you want to match any characters before \EngramEntry_ you have to insert . which means an arbitrary character. This results in the search term:

            .*\\EngramEntry_.

            BUT your replacement string OverrideNamedEngramEntries=(EngramClassName="EngramEntry_ isn’t error-free as well. You need to escape the ( character because it’s a meta character in regular expressions. Thus your replacement string should be:

            OverrideNamedEngramEntries=\(EngramClassName="EngramEntry_

            If you would like to read a really good regular expression manual visit this site. At some points in the manual you have to know the exact flavour of regular expressions used at your site. Notepad++ uses the boost lib regex flavour.

            1 Reply Last reply Reply Quote 3
            • First post
              Last post
            Copyright © 2014 NodeBB Forums | Contributors