• 2 search strings in a group of files with the search function

    3
    0 Votes
    3 Posts
    3k Views
    guy038G

    Hello, Andrea,

    What you, really, like to, is not clearly defined, in your post ! So I tried to guess ;-)

    Seemingly, you’re looking for, either, the string Word1 OR the string Word2, in several files

    As I supposed that these files may contain many occurrences of the string Word1 AND/OR many occurrences of the string Word2 you would prefer to get only ONE result, per file, wouldn’t you ?

    But, as it’s likely that most of them contain the TWO strings Word1 and Word2, do you prefer :

    A) : ONE result, per file, containing ONE of the two strings, whatever it is

    B) : TWO results, per file, with a first line containing ONE of the strings, and a second line containing the OTHER string

    Anyway, I’ll give you the solution for the two cases A) and B ;-))

    Initially, when I built these two regexes, for cases A) et B), I tried them on a dozen, or so, of files, and, unfortunately, I noticed that, when the current file scanned, has an important size, the regex might cause a catastrophic backtracking, ending to a global wrong match of the full contents of this file :-((

    As I was unable to find out other correct regexes, yet, which could avoid search failure, I, then, decided to take advantage of a new N++ feature, implemented since the 6.9.2 version : The new option Find in this finder…, when you right-click inside the Find result panel !

    So, I split the problem in two parts :

    Firstly, output, only, the lines, of each scanned file, which contain, either, the string Word1 and/or Word2, in the Find result panel

    Secondly, from that found restricted list, use my original regexes to get the right results !

    So, follow these preliminary steps, below :

    Open the Find in Files dialog ( Ctrl + Shift + F )

    Type, in the Find what: field, the simple regex (?-i)Word1|Word2

    Type, in the Replace with Field, the regex $0 ( SECURITY ! )

    Type, in the Filters field, your list of files to be scanned

    Type, in the Directory: field, the absolute path of the folder, containing your files

    Click on the Find All button

    => The Find result panel should appear, with all the concerned lines, from all your files to be scanned !

    Notes :

    The (?-i) modifier forces the regex search to be performed in a sensitive way. Use, instead, the (?i) syntax, if you prefer to run the search, in a insensitive way !

    Although we’re just searching something, and not replacing anything, it’s a good habit to, always, put the form $0, which stands for the complete current matched string. Indeed, just suppose that you clicked, by mistake, on the Replace in Files button and that you confirmed the replacement, by clicking on the OK button of the validation dialog, this S/R would simply replace any matched string by this same string itself :-)) Quite at ease, isn’t it ?

    Now, we are going to exploit the restricted text, of the Find result panel :

    Case A) :

    This regex search looks for the last line, in the Find result panel, containing, indifferently, the string Word1 or Word2, in that EXACT case :

    Right-click, inside the Find result panel, and choose the Find in this finder… option

    In the Find what: field, type (?s-i).*\K(?:Word1|Word2)

    Check the Search only on found lines option

    Uncheck the Match whole word only option

    Select the Regular expression search mode

    Click on the Find All button

    => A second “Find result” panel appears, with the indication - Line Filter Mode: only display the filtered results. This new panel should contain, only, ONE line, per file, with, indifferently, the string Word1 or the string Word2 !

    Notes :

    The first part, (?s-i).* , looks for any amount, even empty or multi-lines, of any character ( standard or EOL ) till the last occurrence, in the file, of the string Word1 or Word2, with its exact case, stored in a non-capturing group (?:...|...)

    Due to the \K syntax, the the location of the regex match is reset and the regex engine just matches the string Word1 or Word2

    Case B) :

    This regex search looks for the TWO last lines, in the Find result panel, containing the string Word1, first, then, the string Word2 OR the string Word2, first, then, the string Word1, ans all, in that EXACT case :

    Select, again, the MAIN Find result panel ( IMPORTANT )

    Right-click, inside, and choose, again, the Find in this finder… option

    In the Find what: field, type the regex (?s-i).*\K(?:(Word1)(?=.*(?2))|(Word2)(?=.*(?1)))|.*\K(?:(?1)|(?2))

    Check the Search only on found lines option

    Uncheck the Match whole word only option

    Select the Regular expression search mode

    Click on the Find All button

    => A third “Find result” panel appears, with the indication - Line Filter Mode: only display the filtered results. This new panel should contain TWO lines, per file, with, for each file :

    A first line, containing the string Word1 and a second line, containing the string Word2, in that exact case

    OR

    A first line, containing the string Word2 and a second line, containing the string Word1, in that exact case

    NOTES :

    If a scanned file contains the string Word1 or Word2, ONLY, this unique occurrence is, also, outputted !

    This search regex is quite difficult to understand, because it uses some expressions, called subroutine calls (?n), which point out, by reference, to the groups 1 and 2. Not easy to explain correctly this regex ! I started with the more simple regex, below :

    (?s-i).*\K(?:Word1(?=.*Word2)|Word2(?=.*Word1))|.*\K(?:Word1|Word2)

    After matching the longest range of any character, which is forgotten, due to the \K syntaxt, the regex engine tries to find, either :

    The string Word1, ONLY IF it’s followed, further on, with the string Word2 ( case C )
    OR
    - The string Word2, ONLY IF it’s followed, further on, with the string Word1 ( case D )

    Then, after matching, again, a longest range of any character, which is reset, due to the \K form, the regex engine tries, this time, to find, either :

    The other string Word2 ( case C )
    OR The other string Word1 ( case D )

    The inconvenient of this regex (?s-i).*\K(?:Word1(?=.*Word2)|Word2(?=.*Word1))|.*\K(?:Word1|Word2) is that you must repeat the two strings, to look for, three times to get the overall regex to work ! By using some subroutine calls, we need to enter these two strings ONCE, only, instead of three times !

    In short, the syntax (?n) of a subroutine call, represents the exact contents of group n, which can be located, before, or after, its reference (?n]. So :

    (?1) is equivalent to the group 1, (Word1)

    (?2) is equivalent to the group 2, (Word2)

    Therefore, from the original regex form (?s-i).*\K(?:Word1(?=.*Word2)|Word2(?=.*Word1))|.*\K(?:Word1|Word2), we may change the regex into this final one, below, which is, as correct as the other one, although a bit more difficult to understand :-(. However, you’ll just need to write the two strings to search, only ONCE !

    (?s-i).*\K(?:(Word1)(?=.*(?2))|(Word2)(?=.*(?1)))|.*\K(?:(?1)|(?2))

    Best Regards,

    guy038

    Additional info :

    1) Concerning the new Find in this finder option of the Search result panel :

    If you do NOT check the Search only on found lines option, the search is performed on all the contents of the different files, listed in the Search result panel

    if you check the Search only on found lines option, the search is performed, ONLY, on all the lines, listed in the Search result panel

    2) The main difference between a subroutine call and a back-reference is that:

    A back-reference \n refers to the present value of the group n

    A subroutine call (?n) refers to the present template of the group n

    So, if we consider these four lines :

    123 ABC 123 123 ABC 789 789 ABC 123 789 ABC 789

    The regex (\d+) ABC \1 would match lines 1 and 4, whereas the regex (\d+) ABC (?1) would match the four lines

    In other words, the regexes (\d+) ABC (?1) and (\d+) ABC (\d+) are strictly equivalent

    3) Note that, when a subroutine call is used INSIDE its group, to which it refers, it becomes a recursive sub-pattern reference :

    For instance, in the regex :(\{[^\{\}]+\}(?1)?), the group 1 is the overall regex, which does contain its reference (?1). So (?1) is a recursive sub-pattern reference

    But, in the regex (\{[^\{\}]+\})(?1)?, the group 1 is (\{[^\{\}]+\}) and its reference (?1), located outside the group 1, is just a subroutine call

    These two regexes looks for, either, a single string {....} surrounded by curly braces or two consecutive strings {....}{....}

    You may test these regexes, with the example text, with contains a well-balanced amount of curly braces :

    {This}{is}{a small}{text}{{in order{to {test}{this}}}{{regex}}}
  • Guidance needed - "Bullet Journal" idea for language / plugin

    6
    0 Votes
    6 Posts
    3k Views
    Bob ThomasB

    Thanks for the info guys! I think I have what I need to proceed.

  • Notepad++ inserts text on carriage return

    Locked
    2
    0 Votes
    2 Posts
    2k Views
    Claudia FrankC

    @Atul-Vaidya

    first thing I would try is to start npp without plugins and see if problem still exists.
    Either by renaming the plugin directory or by starting npp with parameter -noPlugin.

    Cheers
    Claudia

  • how to change line spacing

    2
    0 Votes
    2 Posts
    2k Views
    Claudia FrankC

    @Carol-Granger-Umberger-King

    you need to be more specific about what you want to do
    and keep in mind that notepad++ is an editor and not a
    word processor like libre office writer or MS Office Word.

    Cheers
    Claudia

  • Chardet methods integration in a VS C# Project

    Locked
    2
    0 Votes
    2 Posts
    2k Views
    Claudia FrankC

    @EuGeNiO-ChIoDo
    maybe this will help?

    Cheers
    Claudia

  • want Edge not IE in RUN - Launch

    8
    0 Votes
    8 Posts
    5k Views
    Jim Gerland243J

    This works for me:

    Download the MicrosoftEdgeLauncher.exe from https://github.com/MicrosoftEdge/edge-launcher/releases/tag/1.0.0.0 to your C:\Program Files (x86) folder Edit your C:/Users/<put your username here>/AppData/Roaming/Notepad++/shortcuts.xml file In the <UserCommand> secton add this line:
    <Command name=“Launch in Edge” Ctrl=“yes” Alt=“yes” Shift=“yes” Key=“83”>“C:\Program Files (x86)\MicrosoftEdgeLauncher.exe” "$(FULL_CURRENT_PATH)</Command> Exit and reload Notepad++ Open an HTML file and try it.
    Jim…
  • 0 Votes
    15 Posts
    45k Views
    Cecilia DalzellC

    Go raibh maith agat, a guy038! Thank you so much, guy038! Notepad++ has been one of my go-to places to type in Irish (Gaeilge)text without the craziness you get in Microsoft when attempting a bilingual document. I could find nothing about how to reactivate the spellchecker and keyboard in Notepad++'s help, and it was definitely there before my computer was reimaged. Your instructions are most helpful. For the record, I have it working in English and Irish on Notepad++ 7.2.2 64 bit, windows 7 64 bit.

  • Function list with PHP with abstract functions

    7
    0 Votes
    7 Posts
    3k Views
    Florent PagèsF

    Nice!

    RE seem to be so powerful.

  • Ruby Syntax highlight issue

    Locked
    3
    0 Votes
    3 Posts
    3k Views
    dereiusD

    @gstavi I brought this into attention of the Ruby Lexer dev within Scintilla. Hopefully it will be corrected.
    Thanks for the suggestions.

  • Frequently forgetting the current session

    5
    0 Votes
    5 Posts
    3k Views
    gstaviG

    If you want a fix, do your part of debugging. Tinker enough until you come up with a short sequence that reproduces the problem and perhaps then someone will try to fix it in the code.
    Otherwise it is just your problem and nobody cares.

  • Allow to download and install plugin for a non admin user ?

    4
    0 Votes
    4 Posts
    4k Views
    dailD

    When installing Notepad++ (which needs admin access of course) you can tell it to load plugins from the user’s %APPDATA% directory. That way N++ can then be executed by a non-admin user and install plugins (normally through the plugin manager) and the plugins and their config files get stored in the user’s own writeable directory.

    Keep in mind this works for most plugins but not all since some need to have files in the same directory as notepad++.exe (e.g. PythonScript).

  • when i doing new line with enter is writing me on the line:LF CR.

    Locked
    8
    0 Votes
    8 Posts
    3k Views
    Scott SumnerS

    @Florent-Pagès

    Yes, that will work, too, if one has the patience to count 20 items rather than use the View menu approach first proposed. :-)

    Or one could just describe that toolbar button as the one with a “paragraph marker” symbol on it. A backwards P with double vertical line.

  • signs instead of numbers

    Locked
    3
    0 Votes
    3 Posts
    2k Views
    נועם יאגודייבנ

    thanks alot, i fixed that by changing the font,

    the bugged font is “courier new”

  • Multiple search terms replaced with multiple terms

    Locked
    17
    0 Votes
    17 Posts
    7k Views
    Claudia FrankC

    @Alan-Preda

    Alan, your welcome.
    You are right, this setting is set because I only work with utf-8 at all.
    Just to be sure, your question has been answered or is there something left?

    Cheers
    Claudia

  • 0 Votes
    2 Posts
    3k Views
    Claudia FrankC

    @A-Stod

    afaik, user defined languages don’t work with stylers and langs.xml.
    They reside in userDefineLang.xml.

    Cheers
    Claudia

  • Where is file with automatic syntax highlighting?

    6
    0 Votes
    6 Posts
    4k Views
    Pete NorrisP

    @Claudia Frank

    Claudia;

    Thanks! :)

  • How to highlight SVG instructions and attributes?

    Locked
    2
    0 Votes
    2 Posts
    2k Views
    Claudia FrankC

    @Raúl-Eduardo-Cárdenas-S.

    please be more specific. Which language? Why do you expect suggestions?
    What did you do to make suggestions working? etc…

    Cheers
    Claudia

  • How to remove duplicate row in Find result?

    5
    0 Votes
    5 Posts
    6k Views
    Casey CrockettC

    @guy038 Thank You! You went above and beyond.

  • Notepad++ crashed then style.css empty

    Locked
    2
    0 Votes
    2 Posts
    2k Views
    natchlabN

    Ok this has been solved.
    If it happens for you, Notepad++ automatically save the current file in C:\Users\Name\AppData\Roaming\Notepad++\backup

    I feel reassured :D

  • Validate multiple XML files against one xsd?

    Locked
    2
    0 Votes
    2 Posts
    4k Views
    MAPJe71M

    Use a command line tool like XMLStarlet.