I need to replace specific word with random each line



  • 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



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



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



  • @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)))


  • @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



  • @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. :)


Log in to reply