Community

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

    I need to replace specific word with random each line

    Help wanted · · · – – – · · ·
    replace randomize
    3
    6
    1819
    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.
    • Sandroma Valiaro
      Sandroma Valiaro last edited by

      I need to replace facebook.com to be like this facebookabcd.com

      social media website 1 facebook.com
      social media website 2 facebook.com
      social media website 3 facebook.com
      social media website 4 facebook.com
      social media website 5 facebook.com

      to be like this : ( social media website 1 facebook[RANDOM].com )

      social media website 1 facebookabcd.com
      social media website 2 facebookefbd.com
      social media website 3 facebookiarl.com
      social media website 4 facebookmnop.com
      social media website 5 facebooksakl.com

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

        Without an additional plugin, you cannot: ie, the built-in search/replace/regular expression system does not have the ability to do “random” anything.

        Most programming languages have the ability to generate pseudo-random numbers (and thus pseudo-random text). So you would need to learn a programming language, and learn how to generate that text using that programming language. Then you would need to learn how to incorporate that generated text with the original text.

        There are plenty of programming/scripting languages that could easily do that, outside of the Notepad++ environment. There are a handful of programming languages for which Notepad++ has plugins, which will incorporate those languages to give direct access to the Notepad++ environment and the text that’s being edited; you can look through Plugins Admin to find those; you would have to pick one that you were willing to learn that programming language.

        Good luck in learning more about Notepad++ and/or programming.

        update: Once you start, and if you’re using one of the plugins that provide Notepad++ scripting, if you show us your effort, but have questions on how to get things to work, I’d be willing to give more help (assuming I know how to help). (edit 2: change “we’ll” to “I’d”, because I don’t know whether others will be willing to help or not.)

        Sandroma Valiaro 1 Reply Last reply Reply Quote 2
        • Sandroma Valiaro
          Sandroma Valiaro @PeterJones last edited by

          @PeterJones Thanks buddy, I really appreciate your comment I’ll try to find other programs rather than Notepad++

          Alan Kilborn 1 Reply Last reply Reply Quote 0
          • Alan Kilborn
            Alan Kilborn @Sandroma Valiaro last edited by

            @Sandroma-Valiaro said:

            I’ll try to find other programs rather than Notepad++

            I’m not sure if this means that you are going to go off and look for other text editors that you think can perform this bit of magic (hint: you won’t find any), or if you meant you are going to research the solutions Peter tried to steer you towards.

            I know that you are “long gone”, so that’s why I’ll tell you that you can do what you wish with ONE line of Pythonscript code (if you don’t count another line that doesn’t really do anything; just imports random and string:

            editor.rereplace('facebook(?=\.com)', lambda m: m.group(0) + ''.join(random.choice(string.ascii_lowercase) for _ in range(4)))
            
            1 Reply Last reply Reply Quote 3
            • PeterJones
              PeterJones last edited by

              @Alan-Kilborn wrote a one-liner including

              lambda m:…

              … and Perl programmers are accused of being intentionally obtuse. :-)

              Even knowing that lambda functions are anonymous subroutines, I have to spend a few minutes to figure out how that PythonScript is working. And in my limited Python experience, I hadn’t yet encountered (or at least noticed and stored) the throwaway _ variable

              Alan Kilborn 1 Reply Last reply Reply Quote 3
              • Alan Kilborn
                Alan Kilborn @PeterJones last edited by

                @PeterJones

                Actually, I wouldn’t normally have made it a one-liner…except the “answer” here inspired the one-liner-ness. :)

                I think lambda examples with replace are in the Pythonscript docs/examples.

                And _ isn’t really a throwaway variable, technically. It’s just a one-character variable like a or b.

                See? No big mysteries. :)

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