• Login
Community
  • Login

Declare and Underscor Multiple Variables

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
7 Posts 5 Posters 255 Views
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.
  • N
    Nathan Heath
    last edited by Jun 17, 2021, 7:49 PM

    I need the following list of variables to be declared as Double and have underscores in place of whitespace. The list should resemble this variable:
    Double Zimone_Quandrix_Prodigy;

    Double Infuse with Vitality;
    Double Inkling Summoning;
    Double Kasmina Enigma Sage;//Kasmina comma
    Double Killian Ink Duelist;//Killian comma
    Double Lorehold Apprentice;
    Double Lorehold Command;
    Double Lorehold Excavation;
    Double Lorehold Pledgemage;
    Double Maelstrom Muse;
    Double Magma Opus;
    Double Make Your Mark;
    Double Manifestation Sage;
    Double Moldering Karok;
    Double Mortality Spear;
    Double Needlethorn Drake;
    Double Oggyar Battle-Seer;
    Double Owlin Shieldmage;
    Double Pest Summoning;
    Double Practical Research;
    Prismari Apprentice;
    Prismari Command;
    Prismari Pledgemage;
    Quandrix Apprentice;
    Quandrix Command;
    Quandrix Cultivator;
    Quandrix Pledgemage;
    Quintorius Field Historian;
    Radiant Scrollwielder;
    Reconstruct History;
    Relic Sloth;
    Returned Pastcaller;
    Rip Apart;
    Rise of Extus;
    Rootha Mercurial Artist;
    Rushed Rebirth;
    Shadewing Laureate;
    Shadrix Silverquill;
    Silverquill Apprentice;
    Silverquill Command;
    Silverquill Pledgemage;
    Silverquill Silencer;
    Spectacle Mage;
    Spirit Summoning;
    Spiteful Squad;
    Square Up;
    Stonebound Mentor;
    Tanazir Quandrix;
    Teach by Example;
    Tend the Pests;
    Thrilling Discovery;
    Vanishing Verse;
    Velomachus Lorehold;
    Venerable Warsinger;
    Witherbloom Apprentice;
    Witherbloom Command;
    Witherbloom Pledgemage;
    

    Does anyone know how I can accomplish this? I got some great advice for a problem similar to this from PeterJones in another thread. Any help would be appreciated, thank you.

    P A 3 Replies Last reply Jun 17, 2021, 8:24 PM Reply Quote 0
    • P
      PeterJones @Nathan Heath
      last edited by PeterJones Jun 17, 2021, 8:24 PM Jun 17, 2021, 8:24 PM

      @Naeem-Heath ,

      If your data is really like that, and there are no lines that shouldn’t be processed, I would do something like FIND = (?<!Double)\h and REPLACE = _ with regular expression mode. This looks for any horizontal space that isn’t preceded by Double and replaces the space with an underscore.

      If your data has exceptions that aren’t mentioned in your description or in your example text, this of course won’t handle those exceptions.

      I didn’t share my standard boilerplate last time, because I was answering from my phone browser then, but it looks like you will benefit from this standard advice.

      ----

      Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will happily give help on the first one or two data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.

      ----

      Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as literal text using the </> toolbar button or manual Markdown syntax. To make regex in red (and so they keep their special characters like *), use backticks, like `^.*?blah.*?\z`. Screenshots can be pasted from the clipboard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get. Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.

      1 Reply Last reply Reply Quote 1
      • P
        PeterJones @Nathan Heath
        last edited by Jun 17, 2021, 8:28 PM

        @Naeem-Heath

        I didn’t see that not all the lines start with Double, and you seem to be indicating that you want them to.

        • FIND = ^(?!Double)
        • REPLACE = Double\x20
        • MODE = regular expression

        This will find all lines that don’t start with Double, and add Double and a space (\x20 is a regex way of writing a literal space character, but that can be seen and copy/pasted in the forum post)

        </end_of_freebie>

        1 Reply Last reply Reply Quote 0
        • A
          Alan Kilborn
          last edited by Jun 17, 2021, 8:45 PM

          @Naeem-Heath said in Declare and Underscor Multiple Variables:

          Double Oggyar Battle-Seer;

          That text would probably be a problem as well (the hyphen), if what I think is really needed (turning this into code) really is.
          It seems like the solution providers here think through the need more than the questioners.

          1 Reply Last reply Reply Quote 0
          • A
            astrosofista @Nathan Heath
            last edited by Jun 17, 2021, 10:31 PM

            @Naeem-Heath, All:

            If I understood correctly the problem statement, one way to deal with it is by means of two regular expressions.

            The first one will underscore every space, except those what it seems to be commented out. The second regex will declare all the variables.

            Search: (?-s)\x20(?=.+;)
            Replace: _
            
            Search: (?-s)^(?!Double)|^Double_
            Replace: Double\x20
            

            So put the caret at the very beginning of the document, select just the Regular Expression mode, enter the first regex and click on Replace All. Repeat them for the second regex.

            If search and replace issues are recurrent problems, as @PeterJones I would suggest you to read the regex guide in the FAQ section of this forum and start learning how to develop your own solutions. If in doubt, ask for help, but please make an effort to learn.

            1 Reply Last reply Reply Quote 2
            • N
              Nathan Heath
              last edited by Jun 18, 2021, 12:03 AM

              Thank you all. I wanted to know how to solve this myself, but did not exactly know what the information I need is called. Now I know, its regex stuff, I will look into it. Thank you again.

              1 Reply Last reply Reply Quote 1
              • G
                guy038
                last edited by guy038 Jun 18, 2021, 6:38 PM Jun 18, 2021, 6:25 PM

                Hello, @Nathan-heath, @peterjones, @alan-kilborn, @astrosofista and All,

                Here is my contribution, which merge the two regex S/R in one S/R only :

                SEARCH (?-i)^(?!Double|$)|^Double\h

                Replace Double_

                So, from your example :

                Double Infuse with Vitality;
                Double Inkling Summoning;
                Double Kasmina Enigma Sage;//Kasmina comma
                Double Killian Ink Duelist;//Killian comma
                Double Lorehold Apprentice;
                Double Lorehold Command;
                Double Lorehold Excavation;
                Double Lorehold Pledgemage;
                Double Maelstrom Muse;
                Double Magma Opus;
                Double Make Your Mark;
                Double Manifestation Sage;
                Double Moldering Karok;
                Double Mortality Spear;
                Double Needlethorn Drake;
                Double Oggyar Battle-Seer;
                Double Owlin Shieldmage;
                Double Pest Summoning;
                Double Practical Research;
                Prismari Apprentice;
                Prismari Command;
                Prismari Pledgemage;
                Quandrix Apprentice;
                Quandrix Command;
                Quandrix Cultivator;
                Quandrix Pledgemage;
                Quintorius Field Historian;
                Radiant Scrollwielder;
                Reconstruct History;
                Relic Sloth;
                Returned Pastcaller;
                Rip Apart;
                Rise of Extus;
                Rootha Mercurial Artist;
                Rushed Rebirth;
                Shadewing Laureate;
                Shadrix Silverquill;
                Silverquill Apprentice;
                Silverquill Command;
                Silverquill Pledgemage;
                Silverquill Silencer;
                Spectacle Mage;
                Spirit Summoning;
                Spiteful Squad;
                Square Up;
                Stonebound Mentor;
                Tanazir Quandrix;
                Teach by Example;
                Tend the Pests;
                Thrilling Discovery;
                Vanishing Verse;
                Velomachus Lorehold;
                Venerable Warsinger;
                Witherbloom Apprentice;
                Witherbloom Command;
                Witherbloom Pledgemage;
                

                You should get the expected output :

                Double_Magma Opus;
                Double_Make Your Mark;
                Double_Manifestation Sage;
                Double_Moldering Karok;
                Double_Mortality Spear;
                Double_Needlethorn Drake;
                Double_Oggyar Battle-Seer;
                Double_Owlin Shieldmage;
                Double_Pest Summoning;
                Double_Practical Research;
                Double_Prismari Apprentice;
                Double_Prismari Command;
                Double_Prismari Pledgemage;
                Double_Quandrix Apprentice;
                Double_Quandrix Command;
                Double_Quandrix Cultivator;
                Double_Quandrix Pledgemage;
                Double_Quintorius Field Historian;
                Double_Radiant Scrollwielder;
                Double_Reconstruct History;
                Double_Relic Sloth;
                Double_Returned Pastcaller;
                Double_Rip Apart;
                Double_Rise of Extus;
                Double_Rootha Mercurial Artist;
                Double_Rushed Rebirth;
                Double_Shadewing Laureate;
                Double_Shadrix Silverquill;
                Double_Silverquill Apprentice;
                Double_Silverquill Command;
                Double_Silverquill Pledgemage;
                Double_Silverquill Silencer;
                Double_Spectacle Mage;
                Double_Spirit Summoning;
                Double_Spiteful Squad;
                Double_Square Up;
                Double_Stonebound Mentor;
                Double_Tanazir Quandrix;
                Double_Teach by Example;
                Double_Tend the Pests;
                Double_Thrilling Discovery;
                Double_Vanishing Verse;
                Double_Velomachus Lorehold;
                Double_Venerable Warsinger;
                Double_Witherbloom Apprentice;
                Double_Witherbloom Command;
                Double_Witherbloom Pledgemage;
                

                In addition, if you re-run this regex S/R, nothing else is matched and replaced. Nice, isn’t it ?

                Best Regards,

                guy038

                1 Reply Last reply Reply Quote 1
                4 out of 7
                • First post
                  4/7
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors