• HELP! Replace spaces in text ONLY between quotes?

    15
    0 Votes
    15 Posts
    5k Views
    guy038G

    Hi, @alan-kilobrn and All,

    Well, here it is ! I found a regex structure and some variants, which do the trick very nicely ;-))

    Let’s define these 4 variables :

    Srch_Expr = Char|String|Regex

    Repl_Text = Char|String|Regex

    Opn_Del = Char

    End_Del = Char

    Then the Search_Replacement_A, which matches any Srch_Expr, ONLY WHEN located between the Opn_Del and the End_Del delimiter(s), is :

    SEARCH Srch_Expr(?=[^Opn_Del]*?End_Del)

    REPLACE Repl_Text

    Rules and Remarks :

    The Opn_Del and End_Del delimiters represent, both, a single char, which may be :

    Characters already present of the current file

    Characters presently absent in current file and manually added by the user ( Verify with the Count feature they are new chars ! )

    In case, of added delimiters, use, preferably, the Search_Replacement_B, below, which deletes these temporary delimiters, at the same time :

    SEARCH Opn_Del|(Srch_Expr)(?=[^Opn_Del]*?End_Del)|End_Del

    REPLACE ?1Repl_Text

    The Opn_Del and End_Del delimiters must not be identical. If NOT ( usually, cases "...." or '....' ), perform the following regex S/R, first :

    SEARCH Delim(.+?)Delim

    REPLACE Opn_Del\1End_Del

    Then, execute the Search_Replacement_C, which rewrites, as well, the initial double delimiters Delim :

    SEARCH Opn_Del|(Srch_Expr)(?=[^Opn_Del]*?End_Del)|End_Del

    REPLACE ?1Repl_Text:Delim

    In case that the last zone Opn_Del......End_Del ends at the very end of current file, the End_Del delimiter, of the last zone, can be omitted and you’ll use the Search_Replacement_D, below :

    SEARCH Srch_Expr(?=[^Opn_Del]*?(End_Del|\z))

    REPLACE Repl_Text

    The different zones, between delimiters, must be complete, with their matched different delimiters ( Open_Del......End_Del )

    The different zones, between delimiters, may be juxtaposed but NOT nested

    A zone can lie in a single line or split over several lines

    Srch_Expr must not match the Opn_Del delimiter, or part of it

    As an example, let’s use the license.txt file and define :

    Opn_Del &

    End_Del #

    Srch_Expr \w+

    I previously verified that, both, these two symbols do not exist in the license.txt file

    Place one or several zones &......#, anywhere in this file. The zones may be split on several lines, with the OplDel & in a line and an End_Del # on a further line

    So, the appropriate search regex_A is :

    SEARCH \w+(?=[^&]*?#)

    And imagine that we want to surround any word with strings [-- and --], in zones &............#, ONLY. Hence, the replace Regex_A is :

    REPLACE [--$0--]

    With the same delimiters, let’s suppose that we want, this time, to find any single standard char, so the regex (?-s). and to replace it with an underscore _ char

    However, regarding the rules above, this regex should not match the Opn_Del delimiter. This can be achieved with the regex (?-s)(?!&)., giving the following Search_Replacement_A :

    SEARCH (?-s)(?!&).(?=[^&]*?#)

    REPLACE _

    Now, Alan I also found a regex which works when delimiters are simple words as for instance, STT and END and not single characters :

    Regex_E = Srch_Expr(?=(?s-i:(?:(?!Opn_Del).)*?End_Del))

    Unfortunately, due to the negative look-ahead syntax, (?!Opn_Del).), this regex bugges, even with the light license.txt file :-(( You know : the final wrong “all contents” match ! But it works nice when few lines are involved !

    The safe solution, in that case, is to replace word delimiters with char delimiters, first ( for instance STT -> & and END -> # )

    Finally, a possible @mugsys-rapSheet’s solution, much shorter, using the generic Search_Replacement_C, could be :

    SEARCH &|(\x20)(?=[^&]*?#)|#

    REPLACE ?1_:"

    Of course, assuming this text :

    & C:\xxx\name with spaces.txt #

    Then, the leading and trailing spaces, around the absolute paths, would not be deleted anymore but just replaced with _ characters. Thus, the final text would be :

    "____C:\xxx\name_with_spaces.txt____"

    Best regards,

    guy038

  • I need to find the lines which is having three ; in notepad ++

    5
    1 Votes
    5 Posts
    1k Views
    guy038G

    Hello, @bhogesh-waraprasad, @peterjones, @alan-kilborn and All,

    From this discussion, after some tests, here is an other generic regex which selects all the contents of all lines containing, exactly, N to M times, the Char character, per line :

    ^([^Char\r\n]*)(Char(?1)){N,M}$    or    ^([^Char\r\n]*)(Char(?1)){N}\R if you want to match their line-breaks, too

    So, you can, either, mark, delete or replace these lines ;-))

    Notes :

    Char represents a single character, which is, usually, a non-word character ( A punctuation or symbol char )

    N and M must be replaced with the appropriate integers ( For instance {2,4}, {5,}, {0,3}, {2} or even {0} )

    So the search regex OP is ^([^;\r\n]*)(;(?1)){3}$

    Best Regards,

    guy038

  • Copying highlighted text lines from 1 Notepad++ file to another

    22
    0 Votes
    22 Posts
    4k Views
    Alan KilbornA

    @Alan-Kilborn said in Copying highlighted text lines from 1 Notepad++ file to another:

    …how to bind a keycombo to it to execute the script that way (which is better than menuing for an often-used script).

    Some instructions for that are found in THIS POSTING.

  • 0 Votes
    2 Posts
    401 Views
    PeterJonesP

    @John-Slee ,

    Use the ? modifier to make an element of your regex less greedy (“find the shortest”).

    Good luck.

    ----

    Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as plain text using the </> toolbar button or manual Markdown syntax. Screenshots can be pasted from the clipboard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get… Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.

    -----
    I invoked the “Dail Critereon” for my answer

  • Search and relace - how to put in a line break?

    11
    0 Votes
    11 Posts
    610 Views
    EkopalypseE

    Should we create a cheat sheet :-D

  • Emojis Not Showing On Windows 7

    6
    0 Votes
    6 Posts
    1k Views
    Michael VincentM

    @astrosofista said in Emojis Not Showing On Windows 7:

    However, after applying the script you provided, emojis are correctly displayed

    Great! Note that N++ version 7.8.7+ - that is to say whatever version will next be released looks to have this SC_TECHNOLOGY_DIRECTWRITE as an option in the Settings => Preferences => MISC. dialogue.

    But a script for now is just as good while we wait!

    Cheers.

  • Right-clicking file no longer maximizes Notepad++

    2
    0 Votes
    2 Posts
    517 Views
    EkopalypseE

    @Daniel-Hall

    So what did you do that it stopped working? Updated Npp?
    Updated windows? Installed some other app?
    What npp version are you running? (Can be seen as debug-info from ? menu)

  • Find and change using key / dictionary file

    3
    0 Votes
    3 Posts
    657 Views
    Grzegorz KwiatkowskiG

    I found the Advanced Fin and Replace program. However, I was hoping that a brilliant notepad ++ can do that too. I would have one program less on my list;)

    Thank you for your help.

  • Suggestion: Option to Close All before Session Load

    15
    0 Votes
    15 Posts
    1k Views
    Dwayne RobertsD

    @PeterJones My preference would be for the Close All to be executed only when a new session is loaded, and then only optionally (either by a setting or a prompt). I think, for now I’ll just try to remind them at the beginning of each class to Close All before loading the new session. Thanks for the suggestions!

  • 0 Votes
    3 Posts
    2k Views
    Nikhil ChavanN

    Hi @guy038

    Thanks alot!!!
    It worked…😊🍻

  • 0 Votes
    1 Posts
    239 Views
    No one has replied
  • Help with Zenburn Theme

    2
    0 Votes
    2 Posts
    483 Views
    EkopalypseE

    Themes is something that doesn’t really work well in Npp, since, at first,
    it was only designed to “theme” the document, and later it was,
    more or less, adapted to the rest of the ui.
    Glitches like the one you mentioned are therefore unfortunately part of the problem.

  • Upper case letter in replace

    7
    0 Votes
    7 Posts
    397 Views
    Hakunamatata67H

    You’re the best guy038!
    Thank you so much

    Take care

  • how to compress a file to .rar in notepad

    2
    0 Votes
    2 Posts
    365 Views
    andrecool-68A

    Just like making a live cow out of a sausage

  • How to delete a complete tag with specific content

    15
    1 Votes
    15 Posts
    7k Views
    Luiz Antonio Souza RibeiroL

    @guy038 said in How to delete a complete tag with specific content:

    (?s)<Report>(?:(?!</Report>).)<Active>0000000000</Active>.?</Report>

    Thank you. It works for me in a similar case.

  • Find the Line that contains the MD5 code!

    3
    0 Votes
    3 Posts
    385 Views
    Sarah DuongS

    @guy038 Thanks. You’re boss this forum.

  • How change icon per extension (windows)

    4
    0 Votes
    4 Posts
    824 Views
    BobSquarePantsB

    Done,

    So it quite easy. You should let .ini .txt attach to their default apps (notepad.exe)
    and simply change manually the reg info from
    HKEY_CLASSES_ROOT\inifile
    HKEY_CLASSES_ROOT\inifile\shell\open\command pointing to Notepad++
    HKEY_CLASSES_ROOT\inifile\DefaultIcon The .ico of your choice

    and that it.
    You should avoid Windows to make the binding for you :)

  • How to replace all content from XML tag with blank in notepad++?

    6
    0 Votes
    6 Posts
    2k Views
    astrosofistaA

    @PeterJones said in How to replace all content from XML tag with blank in notepad++?:

    Nitpick: it’s the . operator that is affected by (?-s), not the *, since the s flag is “dot matches newline”. But . wasn’t used in your expression, either, so the flag-clearing is still useless. :-)

    Yep, my bad, I stated a wrong reason, thank you for notice it :)

    Well, not completely useless. As we help people in the forums, always including either (?-s) or (?s) will ensure we never have to care what the status of their checkbox is, so having one of the two in our default answer-regex is a good idea. ;-)

    Agree, learned that in this forum, so the (?-s) modifier is my default setup.

    Cheers

  • Windows exclamation macro beeps.. at what ?

    6
    0 Votes
    6 Posts
    409 Views
    guy038G

    Hello, @terry-gaff-0 and All,

    I second what Alan said :

    This sounds like a potentially dangerous situation.
    Well, for your data, not for you.

    Indeed, you must define what to do, when any of your searches is unsuccessful. If you’re using the regular expression search mode, it usually means that some templates, in your data, are not taken in account by the overall regex search expression !

    Best regards,

    guy038

  • Negative number highlighting

    2
    0 Votes
    2 Posts
    329 Views
    EkopalypseE

    @Chris-Betts

    If, for example, I define ( and ) as operators I do get the following

    6aa6ec65-567c-49bf-8d9f-8e74de8492eb-image.png

    How did you define the brackets, as delimiters and if so have you allowed nesting with numbers?