• Replacing word between specific characters

    2
    0 Votes
    2 Posts
    480 Views
    PeterJonesP
    @shpock-boss , In a single step? Not easily. Basically, what you gave would make a good program, written in your favorite language, which would search for URLs and then do all the logic, written in a way that you could understand and maintain in the future. And this isn’t a programming forum or a codewriting service. I was curious, and no one had replied yet, so I ran a few experiments. Using some really complicated regex, I was able to come up with something that worked for up to three directory levels; but every level requires more logic and more nested capture groups. So if you never have more than 3 directories (and if you define a directory’s valid characters the same way I do), then this will work: FIND = (?-s)(https?://[^\s/]+/)([^\s/]+/)(((?2))?(((?2))?(.*))) REPLACE = (?2${1}XYZ/${3})(?4\r\n${1}${2}XYZ/${5})(?6\r\n${1}${2}${4}XYZ/${7}) SEARCH MODE = regular expression https://developers.apple.com/XYZ/profile/ShadowDES/Boy?view=FUZZ https://developers.apple.com/forums/XYZ/ShadowDES/Boy?view=FUZZ https://developers.apple.com/forums/profile/XYZ/Boy?view=FUZZ No, I am not going to explain it in full detail. Basically, it is using capture groups to store various pieces in numbered groups, and using the numbered subexpression control flow to repeat previous conditions later in the match, and nesting groups so that you can reference various layers, For the replacment, it’s using substitution replacements for deciding how many output lines there will be, and what they will look like. But I do not recommend this. Using regex you don’t understand is dangerous, and this is something complex enough that you should only use it if you understand it, and are willing to read the document I linked, and backup your data, and keep experimenting with it until you do understand it. An alternate way, which is slightly easier to understand, would still use conditionals, but the sequence is less complex (no nesting), so you can make it work for more terms by just copying the last term in the search, and copying the pattern Step one of this would be to run a regular expression that would make N copies of the URL, and would add an indicator at the beginning (I chose N ∙ characters) to indicate which level of directory should be replaced on each line. Starting with data https://developers.apple.com/forums/profile/ShadowDES/Boy?view=FUZZ https://developers.apple.com/one/two/three/four/five/six/seven/end.html the end of first step will be ∙https://developers.apple.com/forums/profile/ShadowDES/Boy?view=FUZZ ∙∙https://developers.apple.com/forums/profile/ShadowDES/Boy?view=FUZZ ∙∙∙https://developers.apple.com/forums/profile/ShadowDES/Boy?view=FUZZ ∙https://developers.apple.com/one/two/three/four/five/six/seven/end.html ∙∙https://developers.apple.com/one/two/three/four/five/six/seven/end.html ∙∙∙https://developers.apple.com/one/two/three/four/five/six/seven/end.html ∙∙∙∙https://developers.apple.com/one/two/three/four/five/six/seven/end.html ∙∙∙∙∙https://developers.apple.com/one/two/three/four/five/six/seven/end.html ∙∙∙∙∙∙https://developers.apple.com/one/two/three/four/five/six/seven/end.html ∙∙∙∙∙∙∙https://developers.apple.com/one/two/three/four/five/six/seven/end.html The regex to do this would be FIND = (?x-s)(https?://[^\s/]+/) ([^\s/]+/)? ([^\s/]+/)? ([^\s/]+/)? ([^\s/]+/)? ([^\s/]+/)? ([^\s/]+/)? ([^\s/]+/)? [^\s]* REPLACE = (?{2}∙$0)(?{3}\r\n∙∙$0)(?{4}\r\n∙∙∙$0)(?{5}\r\n∙∙∙∙$0)(?{6}\r\n∙∙∙∙∙$0)(?{7}\r\n∙∙∙∙∙∙$0)(?{8}\r\n∙∙∙∙∙∙∙$0) If you need more than seven directories deep, add another ([^\s/]+/)? in the sequence of those in the FIND, and another (?{ℕ}\r\n∙∙∙∙∙∙∙$0) at the end of the REPLACE The second and following steps would look for 7 ∙ symbols followed by a URL, then 6, then 5, then … on down, replacing the right piece in each one: FIND = (?x-s) ∙{7} (https?://[^\s/]+/) (([^\s/]+/){6}) (?3) (.*$) for each time, the numbers in the curly braces in the FIND would each decrease by 1, so it’s 7 and 6 for the seventh subdir, 6 and 5 for the sixth subdir, and so on down. (I did confirm that {0} will properly match 0 instances of the match, so it even works on the final pair of 1 and 0.) REPLACE = ${1}${2}XYZ/${4} After all of those, I had: https://developers.apple.com/XYZ/profile/ShadowDES/Boy?view=FUZZ https://developers.apple.com/forums/XYZ/ShadowDES/Boy?view=FUZZ https://developers.apple.com/forums/profile/XYZ/Boy?view=FUZZ https://developers.apple.com/XYZ/two/three/four/five/six/seven/end.html https://developers.apple.com/one/XYZ/three/four/five/six/seven/end.html https://developers.apple.com/one/two/XYZ/four/five/six/seven/end.html https://developers.apple.com/one/two/three/XYZ/five/six/seven/end.html https://developers.apple.com/one/two/three/four/XYZ/six/seven/end.html https://developers.apple.com/one/two/three/four/five/XYZ/seven/end.html https://developers.apple.com/one/two/three/four/five/six/XYZ/end.html I give you this solution because it’s easier to extend to work with more subdirectories if you’ve got huge URLs. But it’s still a multistep process. I think this has less room for error than the previous one, but still back up your data and study the resources given, and see if you can understand each piece. caveat emptor This suggestions given seemed to work for me, based on my understanding of your issue, and is published here to help you learn how to do this. I make no guarantees or warranties as to the functionality for you. You are responsible to save and backup all data before and after running anything contained herein. If you want to use it long term, I recommend investing time in adding error checking and verifying with edge cases, and making sure you understand every piece of any of the suggestions.
  • Default Directory - So Annoying

    2
    1 Votes
    2 Posts
    413 Views
    Alan KilbornA
    @Courtney-Fay People get so “uppity” about software they pay zilch for. It can be amazing at times… So the dialogs for opening and saving files were changed out recently. This was determined to be such a needed change, that it actually ended Notepad++ support for Windows XP (but that’s a side note), but it brought (mostly) improved functionality. Anyway, several unexpected consequences resulted from that swap out, and one of them happens to be the issue you mention. Your options: Go to a slight earlier version than 7.9.5 (probably 7.9.2 will do it) or try the new 8.0 release candidate (where the problem you describe should be fixed).
  • Highlight specific part within a word/text

    2
    0 Votes
    2 Posts
    409 Views
    PeterJonesP
    @thomyka , In a UDL, you should be able to make step a keyword, rather than trying to split it into some strange set of operators or delimiter pair. But maybe I haven’t understood what you want correctly.
  • CRLF inserts Parenthesis and True, and Comma's on next line

    6
    0 Votes
    6 Posts
    2k Views
    Bryce HartfordB
    @Marcos-Ferreira Hey Marcos, I did not see your reply, but did go through every plugin in, and 1 by 1, uninstalled, restarted NPP and tested. And guess what?! It was indeed “NPPCalc” that was causing the issue. After reading comments on that plugin, I decided I don’t need it anyway. So now I can CR/LF all day long without those annoying characters. Thank you for confirming! Bryce
  • add line breaks without breaking word

    line separator help help macros paragraph
    5
    0 Votes
    5 Posts
    961 Views
    Abed99A
    PeterJones mention a good way and here is another way using regex: search for :(\w+\.?!?\s){2} replace with : $&\r\n search mode : regular expression change 2 to the X amount of characters you want [image: 1621529094140-3.png]
  • 0 Votes
    7 Posts
    7k Views
    OzBobO
    @Max-Lovic has provided a nice looking solution. How can this be merge into the main notepad++ repo? I tried removing all the ‘styles’ from userDefineLang.xml which did not work.
  • Replace a character by using a list of names

    2
    0 Votes
    2 Posts
    402 Views
    Daniel FuchsD
    I am afraid this is not possible with the build-in Replace function. You could however install the PythonScript plugin, where you can then script such a replace.
  • End python script execution

    pythonscript
    5
    0 Votes
    5 Posts
    1k Views
    claudio pergolinC
    i resolved. thank you
  • Pythonscript :RuntimeError

    5
    0 Votes
    5 Posts
    974 Views
    claudio pergolinC
    thanks for the tip to both of you
  • Npp too many profiles

    3
    0 Votes
    3 Posts
    511 Views
    Michael VincentM
    @Jonathan-MICHELON said in Npp too many profiles: But now i’ve got a problem, too many profiles are in the list. What version of NppFTP are you using? Both the latest and the latest pre-release both offer grouping of individual profiles: [image: 1621368749737-4296ed23-1050-4a04-b687-96d583dfe3f8-image.png] Cheers.
  • Confused by Replace versus Replace-All

    8
    0 Votes
    8 Posts
    1k Views
    AdrianTweeterA
    Thank you Terry and Alan for the detailed answer to my question. I have seldom used the \K and so had not run into the problem before. Your explanations of why the behaviours are different are very interesting.
  • How to find unclosed / hanging tags?

    unclosed tags
    3
    0 Votes
    3 Posts
    5k Views
    Ramanand JhingadeR
    Thanks @Michael-Vincent I used this HTML validator
  • nppBackup lost

    2
    0 Votes
    2 Posts
    374 Views
    Jean-Pierre MoulardeJ
    I eventually found the answer. It’s not obvious, at least in the French version.
  • UDL for rmarkdown = R + markdown/LaTex?

    10
    0 Votes
    10 Posts
    2k Views
    ddalthorpD
    @Ekopalypse Dang. I was looking for a quick fix. UDL does an amazing job with the limited tools it employs; I was hoping that a simple tweak would get me there. I’m seriously considering dumping Windows and moving to Linux before too long (after finishing up a couple projects), so I’m not going to sink any more time into coming up with a good windows solution with Npp.
  • Captions for video - Find and Replace across time stamps

    30
    0 Votes
    30 Posts
    6k Views
    Alan KilbornA
    So in attempting to get something to work, I’ve come up with the following regular expression replacement (generated via code): find: (?(DEFINE)(?<TS>\d{1,3}:\d{2}:\d{2}\.\d{3},\d{1,3}:\d{2}:\d{2}\.\d{3}))like(?<RE>\x20|\R|\R*(?<TSLINE>(?P>TS))\R)a(?P>RE)fire repl: it so that it will \r\n\r\n$+{TSLINE}\r\nliquify And running it on this data: 0:00:17.680,0:00:20.400 vaporize like a 0:00:19.840,0:00:22.400 fire 0:00:17.680,0:00:20.400 vaporize like a 0:00:19.840,0:00:22.400 fire Should produce this result: 0:00:17.680,0:00:20.400 vaporize it so that it will 0:00:19.840,0:00:22.400 liquify 0:00:17.680,0:00:20.400 vaporize it so that it will 0:00:19.840,0:00:22.400 liquify But it is ignoring my use of $+{TSLINE} in the replace expression and produces the following: 0:00:17.680,0:00:20.400 vaporize it so that it will liquefy 0:00:17.680,0:00:20.400 vaporize it so that it will liquefy It is working fine in the Boost emulation mode for RegexBuddy, just not in Notepad++. Any ideas? I’m also open to someone changing the regexes I’m using. Given that this is a general problem with a complicated regex situation between every word in a multiple word search string, I thought it better to switch to named groups instead of numbered groups, but as of yet I don’t feel confident with any approach.
  • 0 Votes
    8 Posts
    3k Views
    KubaK
    Gentlemen! Thank you very much for your help. Everything works like a charm. Your experience is invaluable!
  • replacing complexity

    6
    0 Votes
    6 Posts
    2k Views
    Alan KilbornA
    @Matt-Whitlock said in replacing complexity: Is there any place you would recommend to learn more about how to use notepad++? I can’t offer much truly on this. Experimentation is often the best teacher. Use it! But the things you have asked about in your posts aren’t really Notepad++ things, they are “regular expression” data manipulation things. Regular expressions aren’t a Notepad++ concept, but rather a general concept. And I already told you to check the FAQ about learning more about that. For Notepad++ in general, reading this forum is a great place. The user manual found HERE is also good, although it, like most manuals, is a reference, not a “how to”.
  • split line help requested

    split newline
    4
    1 Votes
    4 Posts
    479 Views
    Matt WhitlockM
    Thank you for the replies friends. <3
  • Select a path between words

    2
    0 Votes
    2 Posts
    425 Views
    PeterJonesP
    @ArkadiuszMichalski , The three levels of single-click, double-click, and triple-click select single caret position, current word, and whole line. The way to get the behavior you want is to change teh definition of “word”, which you can do by setting Settings > Preferences > Delimiter > ☑ Add your characters… = :\ I know there have been PythonScript examples of highjacking double-click as well (using the scintilla notifications and callbacks), so if you didn’t want to change the definition of “word” you could solve it another way. NppExec can do a lot, but I don’t think it can handle the notification callbacks. NppExec might be able to create a script that goes from the current position, and searches both forward and backward until it hits a space in either direction – but I usually think of NppExec as more of a batch-scripting, for interacting the entire contents of the file with external programs, and think of character-based as something better suited for PythonScript or similar, so I’m not sure how I would go about solving that problem in NppExec.
  • [Bug Report] Clickable links not completely working.

    8
    0 Votes
    8 Posts
    2k Views
    Alan KilbornA
    @Ben-Hutchinson I really think you should read and try to understand my earlier posting. Hint: I wasn’t complaining that the link wasn’t a real one. I think your real problem is that N++ 6.9.2 is sort of an old version. Suggest you try something newer, perhaps 7.9.5.