• How to find and highlight a specific occurance of a symbol?

    14
    0 Votes
    14 Posts
    6k Views
    Scott SumnerS

    @guy038 and @Terry-R :

    So after some thinking about this, I’ve decided that I don’t think the \A syntax is broken in Notepad++, and I don’t think that lookbehind assertions (either positive or negative) are broken in Notepad++ either. One just has to fully understand how Notepad++ searching works. And @guy038, in your post just above, where you talk about a “first problem” and a “second problem” and beyond…I have NO problem with how Notepad++ works in these cases, given my new thinking!

    Every Notepad++ search has a “starting-point” when the user initiates a search, or that Notepad++ itself initiates after a successful match in the case where one of the “find all” searches (or a Find in Files) is conducted. Each starting-point has exactly NOTHING before it. YOU may SEE data before your caret when you initiate a Find Next, but Notepad++ doesn’t. And that, IMO, isn’t necessarily a broken search feature, it is just “the way it works”. To Notepad++, each starting-point appears the same as a start-of-file does–no data (aka NOTHING) comes before it.

    At the beginning of your regex, an \A assertion or ANY valid negative lookbehind assertion will match the NOTHING right at a starting-point (i.e., that part of the regex will always succeed). Note that a negative lookbehind assertion doesn’t match the real data to the left of your caret, it matches the NOTHING. Example: Have 12345678 (only) in your buffer and your caret between the 4 and the 5. Do a regex search for (?<!4)5 and see that it matches the 5. The (?<!4) in this case allows the match because NOTHING is not 4. Some would call this regex behavior “broken”…because YOU the user can see the darned 4 right there!

    While a search is “in-progress” on a buffer, however, no one would call negative lookbehind assertions broken. Example: Use the same buffer as before but have your caret between the 1 and the 2. Do a regex search for (?<!4)5 and see that there is no match. In this case there is a 4 before the 5 (the search is “underway” at this point and Notepad++ is looking at the buffer…and this time the 4 is a part of that buffer) so the assertion fails the overall match.

    Side note: With “Wrap around” ticked during a search, if no match is found between the current caret point and the end-of-file, a second (internal) search is done by Notepad++, with a starting-point at the start-of-file. This is an additional opportunity for a match to happen at a “starting point”. For more info on the “2nd search”, see here…quite far into that thread… Although that thead discusses replacement, find a part of replacement, so it works the same way.

    So that brings us back to the regex under discussion: (?<!\r|\n)^.

    It will work like an “unbroken” \A in most cases. A possible problem with it comes when doing “multiple” searches with it (or when the user-starting-point isn’t the start-of-file). In those cases, if the previous action with it leaves the next starting-point at the start of any line, the next search will match right there – not only at start-of-file – which may not be what the user desires. (Again, it will match that case because the (?<!\r|\n) part will match the NOTHING and the ^ will hit).

    The best way to use it as an \A-equivalent is to have the end of your regex not leave the next starting-point at any start-of-line.

    So let’s go back to Terry’s original regex (or very close to it):

    (?s)(?<!\r|\n)^((.+?)===========){5}(.+?)\K(===========)

    When run on the OP’s sample data (duplicated a few times so that there are many more than 9 lines of =========== data) this will find exactly ONE match when a “find all” is done. That is because the end of the regex sets up the follow-on starting-point to NOT be able to match a start-of-line (needed by the ^ assertion).

    Changing the regex slightly at the end:

    (?s)(?<!\r|\n)^((.+?)===========){5}(.+?)\K(===========)\R

    This one will result in multiple matches using a “find all” in the OP’s (extended) data, for reasons which should now be apparent. Thus it is worth pointing out in such a case that the (?<!\r|\n)^ regex is NOT what one normally thinks \A should be doing. So while it can be a \A substitute, it still has to be used with some amount of caution, and of course, understanding. :-)

    Back to \A: You can be the judge of whether or not it is broken: The Boost documentation for \A says “Matches at the start of a buffer only” – does one consider the “buffer” to be the entirety of the Notepad++ editor tab data, or the starting-point(s) through a later point for a search? Your call. :-)

    And now onto \G. In this thread , there are 3 conditions specified for where the \G assertion can match. I believe there is only ONE place it can match; hint: the “starting-point” of a search. :-)

  • 0 Votes
    2 Posts
    1k Views
    Vitaliy DovganV

    It already works like you described in your feature request.
    I can only assume that double-clicking the find results may not work properly when you are working with remote files (e.g. via network, mapped network drive, FTP etc.) and there’s something wrong with getting the proper file path.

  • Add href expression as exeption

    Locked
    1
    1 Votes
    1 Posts
    569 Views
    No one has replied
  • Macro not behaving the same as keystrokes

    5
    1 Votes
    5 Posts
    2k Views
    Russ FisherR

    Thank you Peter and guy038,

    Both solutions are very elegant, but I chose to use guy038’s - it works like a champ! This make coding with auto-complete symbols and tags so much easier.

    I cut my programming teeth editing in Wordstar on CP/M machines (ok, my age is showing and many of you young folks have no clue what I’m talking about.) This was before there were cursor directional keys and all cursor movements were done with <Ctrl>-? sequences. I’m a relatively fast touch typist and hate leaving the home row to find <End>, <Home>, <Left-arrow> etc. I’ve also swapped the position of the <Ctrl> and <Caps lock> keys (registry hack) to put <Ctrl> back where God (and IBM) intended to be.

    Thanks again for your help.
    Cheers,
    Russ

  • Please help me to replace text like the following condition

    Locked
    3
    0 Votes
    3 Posts
    1k Views
    Nguyen WanderozN

    @guy038 said:

    Replace All

    Hello @guy038 ,

    Thank you very much! It worked like magic!!! And your crystal cleared explaination make a dummy like me can get to understand. Surely, I need to start to learn about regular expressions.

    Best Regards,
    Wanderoz

  • Need help to replace tags to one xml from another xml

    22
    0 Votes
    22 Posts
    7k Views
    ganesan govindarajanG

    @Terry-R

    Thank you so much!

    I will check that link and try to get resolve myself.

    ganesang

  • Want to see all my posts

    Locked
    3
    0 Votes
    3 Posts
    807 Views
    C Ananda RaoC

    Thanks Mr Terry R!

  • This "»" Changes to This "禄"

    Locked
    1
    0 Votes
    1 Posts
    716 Views
    No one has replied
  • 0 Votes
    4 Posts
    3k Views
    PeterJonesP

    Sorry, I have no host recommendations; my host also doesn’t play with NppFTP’s algorithms, but since FileZilla was already my file-transfer app of choice, it wasn’t that difficult for me to change my workflow from using the NppFTP plugin in Notepad++ to using Notepad++ as the editor-application for FileZilla (as described in my link, above).

  • Compare a whole file with several files / a directory

    5
    0 Votes
    5 Posts
    3k Views
    Stephan RS

    Hi @guy038
    this is working perfectly! Many thanks for the work that you put in my special (and probably unique) query! You saved my day! ((:

    Best Regards,
    Stephan

  • Is there any plugin to search specific word within the specific method?

    4
    2 Votes
    4 Posts
    1k Views
    guy038G

    Hi, @publicst, @claudia-frank and All,

    A similar and more simple regex could be :

    SEARCH (?s-i)void method[^}]+for.+?\}

    Cheers,

    guy038

  • Deleting all numbers with specific letter(s)

    Locked
    8
    0 Votes
    8 Posts
    2k Views
    Berniukas NeziniukasB

    @guy038 Sorry for being unclear! Sometimes I read my older posts and wonder how people managed to find any sense in them. That’s why I post so rarely…

  • Regex: Find words between words

    Locked
    4
    2 Votes
    4 Posts
    2k Views
    Vasile CarausV

    thank you

    also,

    a(\W+\w+){1,6}\W+for

  • Seperate a format in rows

    Locked
    3
    0 Votes
    3 Posts
    838 Views
    guy038G

    Hello @ph0enix, @Scott-sumner and All,

    if the general template of your data is always :

    ........@..........;......

    Here are, below, 3 other possible regex S/R. Similarly to Scott’s post, you must select the Regular expression search mode, tick the Wrap around option and click on the Replace All button. Note that the Replace with: zone is always Empty

    First regex :

    SEARCH (?-s)@.+

    REPLACE Empty

    Results :

    123.456.78.0:22000 12.3.456.789:10000

    Second regex :

    SEARCH (?-s).+?@|;.+

    REPLACE Empty

    Results :

    Name\Name123 NAME\Name-1

    Third regex :

    SEARCH (?-s).+;

    REPLACE Empty

    Results :

    name Name2017

    Best Regards,

    guy038

  • Delete Individual Lines in Multiple Files based on a List

    Locked
    3
    1 Votes
    3 Posts
    2k Views
    Darren WhiteD

    Scott, Thank you. I knew there would be a way and I almost knew it would be something in a regular expression, but only gods like yourself would know what to do. I really like the idea of a delimeter and then using the search to match any above and below the line.

    I did not get the chance to try this (although I can’t see why it wouldn’t work) as I thought of an alternative, which was to use Excel and a formula. I managed to open each of my 5 files in one workbook with seperate tabs and use a formula to look at a control tab to find any matches. I think it’s pretty much the same thing as your suggestion, just using vba and not regex.

    I thank you for your efforts

  • how to move cursor to begining of next line

    Locked
    2
    0 Votes
    2 Posts
    2k Views
    Scott SumnerS

    @Allan-Biggs

    Try pressing Alt+Home in your macro where you are pressing Home.

  • Silent Install in specific language

    Locked
    1
    0 Votes
    1 Posts
    2k Views
    No one has replied
  • Can Regex paste values into another file?

    Locked
    11
    0 Votes
    11 Posts
    3k Views
    Scott SumnerS

    @C-Ananda-Rao

    Well, when I asked for data, I guess I should have asked for an explanation of that data to accompany it… I suppose I assumed that the phone number was the last part of every line where digits were present. Anyway, hopefully @guy038’s response provides the help you needed.

  • Can't type "{" or "["

    Locked
    1
    0 Votes
    1 Posts
    784 Views
    No one has replied
  • De-Deuplicate chunks of text? (screenshot)

    Locked
    2
    0 Votes
    2 Posts
    673 Views
    Terry RT

    Well @John-Drachenberg I’d try and grab the records in the group of 5 lines from the date added to the url line, combining them all into 1 line (so replacing CR/LF) with some other delimiter. I’d then create a "key at the start of the line, possibly the main part of the url, excluding any /folder names. Sort all the lines so that it would easily match up possible duplicate urls. To my mind a duplicate is any url where even if the /folder names/ portion was different would warrant further inspection.

    At this point either eyeball the duplicates, or another regex could mark possible duplicates for further inspection.

    Not sure if you actually want a regex to just remove duplicates in the original file, or would be happy just getting a list of possible duplicates which you could then check against the original and remove manually.

    Terry