• Login
Community
  • Login

I need to replace specific word with random each line

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
replacerandomize
6 Posts 3 Posters 3.0k 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.
  • S
    Sandroma Valiaro
    last edited by May 6, 2019, 2:26 PM

    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
    • P
      PeterJones
      last edited by PeterJones May 6, 2019, 2:59 PM May 6, 2019, 2:56 PM

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

      S 1 Reply Last reply May 6, 2019, 3:20 PM Reply Quote 2
      • S
        Sandroma Valiaro @PeterJones
        last edited by May 6, 2019, 3:20 PM

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

        A 1 Reply Last reply May 6, 2019, 5:30 PM Reply Quote 0
        • A
          Alan Kilborn @Sandroma Valiaro
          last edited by May 6, 2019, 5:30 PM

          @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
          • P
            PeterJones
            last edited by May 6, 2019, 6:54 PM

            @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

            A 1 Reply Last reply May 6, 2019, 7:05 PM Reply Quote 3
            • A
              Alan Kilborn @PeterJones
              last edited by May 6, 2019, 7:05 PM

              @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
              6 out of 6
              • First post
                6/6
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors