• UDL: Colon(:) at end of line as a keyword to style the whole line

    Locked
    1
    0 Votes
    1 Posts
    1k Views
    No one has replied
  • Prefixes for numbers don't work with letters, when using own syntax

    4
    0 Votes
    4 Posts
    3k Views
    Сергей Чепцов68С

    @PeterCJ-AtWork Thanks a lot! It works - prefix 2 and extras 1. Really confusing…

  • Clean a file using Regex

    Locked
    3
    0 Votes
    3 Posts
    2k Views
    guy038G

    Hi all,

    In my previous post, I gave a general method to replace a specific character by an other, everywhere in lines of a delimited text, except for a range, between column c1 and c2. I now give you an extension of that method to SEVERAL fixed zones to exclude !

    I mean :

    ^---------- Zone 1 to exclude ------------ Zone 2 to exclude -------------------- Zone 3 to exclude ------------$

    So, let’s suppose the original text, below :

    abcd,04,,11111111, 22,ANYWORD ,ANYWORD,ANY,QZERTY,001,,5555,,AN,Y ANY,pqrst,00x,ANYWORD ,ANYWORD,9A9 ,Last Field, fghi,02,,22222222, 22,ANY ,ANY, WORDS, ANY,AZERTY,999,,6666,,ANY AN,Y,uvwxy,01y,ANY ,ANY, WORDS,,7Z3 ,Last Field, klmn,09,,33333333, 22,WORDS,ANY, WORDS,ANY,TEST-1,123,,7777,,ANY,,ANY,zabcd,02z,,ORDS,ANY, WORDS,3H5 ,Last Field,

    I defined 3 zones to exclude, where the comma character will NOT be changed, while the S/R process :

    The zone 1, which starts at column 26 and ends at column 52 => S1= 26 and E1 = 52 The zone 2, which starts at column 65 and ends at column 72 => S2= 65 and E2 = 72 The zone 3, which starts at column 84 and ends at column 99 => S3= 84 and E3 = 99

    As previously explained, we, temporarily, add the # or @ boundaries, in order to delimit these 3 zones, with the general S/R, below :

    ^(.{S1-1})(.{E1-S1+1})(.{S2-E1-1})(.{E2-S2+1})(.{S3-E2-1))(.{E3-S3+1})..............(.{Sn-En-1-1})(.{En-Sn+1})

    With the given values of S1 through E3 above, we get the following S/R :

    SEARCH : ^(.{25})(.{27})(.{12})(.{8})(.{11})(.{16})

    REPLACE : \1#\2@\3#\4@\5#\6@

    which gives us the delimited text, below, with the boundaries :

    abcd,04,,11111111, 22,#ANYWORD ,ANYWORD,ANY,QZERTY@,001,,5555,,#AN,Y ANY@,pqrst,00x,#ANYWORD ,ANYWORD@,9A9 ,Last Field, fghi,02,,22222222, 22,#ANY ,ANY, WORDS, ANY,AZERTY@,999,,6666,,#ANY AN,Y@,uvwxy,01y,#ANY ,ANY, WORDS,@,7Z3 ,Last Field, klmn,09,,33333333, 22,#WORDS,ANY, WORDS,ANY,TEST-1@,123,,7777,,#ANY,,ANY@,zabcd,02z,#,ORDS,ANY, WORDS@,3H5 ,Last Field,

    Then, running the second regex S/R, below :

    SEARCH : ,(?=[^@]*#)|,(?![^#]*@)|(#|@)

    REPLACE : (?1:_)

    we obtain the final text :

    abcd_04__11111111_ 22_ANYWORD ,ANYWORD,ANY,QZERTY_001__5555__AN,Y ANY_pqrst_00x_ANYWORD ,ANYWORD_9A9 _Last Field_ fghi_02__22222222_ 22_ANY ,ANY, WORDS, ANY,AZERTY_999__6666__ANY AN,Y_uvwxy_01y_ANY ,ANY, WORDS,_7Z3 _Last Field_ klmn_09__33333333_ 22_WORDS,ANY, WORDS,ANY,TEST-1_123__7777__ANY,,ANY_zabcd_02z_,ORDS,ANY, WORDS_3H5 _Last Field_

    As expected, all the commas, located from column 26 till column 52, from column 65 till column 72 and from column 84 till column 99, have NOT been changed into an underscore character !

    Notes :

    In comparison to the previous regexes, only the look-aheads of the second S/R, are slightly different :

    The positive look-ahead (?=[^@]*#) verifies that, from the cursor location, a # character, can be found further, on the current line scanned, without any @ character, between the cursor location and the # location

    The negative look-ahead (?![^#]*@) verifies that, from the cursor location, a @ character, cannot be found further, on the current line scanned, without any # character, between the cursor location and the @ location

    Cheers,

    guy038

  • New to notepad and html; work won't show up in browsers

    Locked
    3
    0 Votes
    3 Posts
    5k Views
    Ellen Brewer JohnE

    Thank you very much for your reply! I was able to sort out my issues.

  • 0 Votes
    1 Posts
    1k Views
    No one has replied
  • search and select files that contains a particular languages

    Locked
    1
    0 Votes
    1 Posts
    995 Views
    No one has replied
  • Use regex to replace backspace by underscore

    Locked
    7
    0 Votes
    7 Posts
    8k Views
    Mauricio SalazarM

    Thank you, it worked well

    Best Regards

  • 0 Votes
    7 Posts
    5k Views
    Stefan1200S

    With Notepad++ v7 I still have this problems. Can someone help fixing this? Thanks in advance. :)

  • New file on "Folder as Workspace", is that a way?

    Locked
    1
    1 Votes
    1 Posts
    1k Views
    No one has replied
  • What is plugins for v7 x64?

    Locked
    1
    0 Votes
    1 Posts
    2k Views
    No one has replied
  • See all files in save dialog

    Locked
    2
    0 Votes
    2 Posts
    2k Views
    Scott SumnerS

    If you don’t mind tripling the amount of typing, entering this in the “File name:” box and pressing Enter seems to achieve what you want:
    *.*

    It’s really just the “All types” mask, but quicker than choosing “All types (*.*)” from the dropdown.

    Cheezy solution, I know…but I use it myself, rather often. :)

  • Suddenly hangs and my file data is erased automatically

    Locked
    1
    0 Votes
    1 Posts
    1k Views
    No one has replied
  • What is "Open session in a new instance of Notepad++"?

    Locked
    1
    0 Votes
    1 Posts
    1k Views
    No one has replied
  • 0 Votes
    1 Posts
    1k Views
    No one has replied
  • Open with NPP from a right-click on .htm file opens file in IE

    Locked
    1
    0 Votes
    1 Posts
    1k Views
    No one has replied
  • Synchronised scrolling across all open files?

    Locked
    2
    0 Votes
    2 Posts
    2k Views
    Scott SumnerS

    How about the keyboard shortcut for moving to the end of document (default: Ctrl+End)? Sure, you’d have to do it in each document, but it is only one (quick) action…

  • Help with Notepad

    Locked
    3
    0 Votes
    3 Posts
    2k Views
    cipher-1024C

    Menu bar -> Language -> INI file

    You will probably get faster/better responses if you include more information about what you’re trying to do.

  • RegEx Replace button doesn't work as expected with a look-behind.

    Locked
    5
    1 Votes
    5 Posts
    3k Views
    dailD

    Title updated.

  • Regex: Double your words

    13
    0 Votes
    13 Posts
    9k Views
    guy038G

    Hello Glenn,

    Oh yes, Glenn you’re thousand times right ! I should have re-read my reply, before posting ! Sorry, for being approximative !

    So, given the S/R, below :

    SEARCH : (?-s)(?:.*\R){26}\K.*(?s)(.*)

    REPLACE : String replacing line 27\1

    Updated Notes :

    The in-line modifier (?-s) forces the regex engine to consider that the dot meta-character will match standard characters, only

    The non-capturing group, repeated 26 times, (?:.*\R){26} selects the first 26th complete lines, with their EOL characters, of each file

    The \K syntax suppresses that selection and reset the regex position of search between the last EOL character of line 26 and the first character of line 27

    Then the .* part, look for all the standard characters, even 0, of the 27th line, which have to be replaced

    Then, the in-line modifier (?s), now, forces the regex engine to consider that the dot meta-character will match any character ( standard OR End Of Line character )

    So, the final part, (.*), inside round parentheses, defines the group 1, containing all the text, from the EOL characters of line 27 … to the very end of the file

    In replacement, the expression String replacing line 27 represents, the new replacement text and the \1 syntax represents the text from the EOL characters of line 27 … to the very end of the file, which must be re-written without any change !

    With that work-around, glennfromiowa, I don’t need to write \r\n, in the replacement regex, for the EOL characters of the line 27 !!

    Many thanks again, for pointing out these approximations ! Indeed, from now on, I’ll have to be careful, because some people, like you, read my posts, word after word :-))

    Best Regards,

    guy038

    P.S. :

    As I’m a moderator of the Node BB Notepad++ forum, I’m going to update my previous post, about that topic , by adding a link to that present post ! So, anyone will, easily, see the differences :-)

  • Duplicate rows according to whats in a column?

    Locked
    4
    0 Votes
    4 Posts
    3k Views
    guy038G

    Hi Greg and Joe,

    Joe, concerning the SEARCH regex, I suppose that you meant, ( with some more star meta-characters ! ) :

    SEARCH = ^(.*?,.*?,.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),$

    Then, with :

    REPLACE = \1,\2\r\n\1,\3\r\n\1,\4\r\n\1,\5\r\n\1,\6\r\n\1,\7\r\n\1,\8\r\n\1,\9

    it would, indeed, match the line, with 8 addresses, below

    10.16.64.0/24,ABC,Prod,10.16.64.0,10.16.65.0,10.16.66.0,10.16.67.0,10.16.68.0,10.16.69.0,10.16.70.0,10.16.71.0,

    and changed it into the block of 8 lines, below :

    10.16.64.0/24,ABC,Prod,10.16.64.0 10.16.64.0/24,ABC,Prod,10.16.65.0 10.16.64.0/24,ABC,Prod,10.16.66.0 10.16.64.0/24,ABC,Prod,10.16.67.0 10.16.64.0/24,ABC,Prod,10.16.68.0 10.16.64.0/24,ABC,Prod,10.16.69.0 10.16.64.0/24,ABC,Prod,10.16.70.0 10.16.64.0/24,ABC,Prod,10.16.71.0

    Unfortunately, if a line, of Greg’s text, has less than eight addresses, at the end, your regex would not work :-((

    But, thanks to you, you put me in the good direction and gave me an idea for getting all the work done, with ONE regex ONLY !!

    So, I start with the example text, below, which contains all possible cases, from no address to 8 addresses, after the environment field, of each line :

    10.16.64.0/24,ABC,Prod, 10.16.64.0/24,ABC,Prod,10.16.64.0, 10.16.64.0/24,ABC,Prod,10.16.64.0,10.16.65.0, 10.16.64.0/24,ABC,Prod,10.16.64.0,10.16.65.0,10.16.66.0, 10.16.64.0/24,ABC,Prod,10.16.64.0,10.16.65.0,10.16.66.0,10.16.67.0, 10.16.64.0/24,ABC,Prod,10.16.64.0,10.16.65.0,10.16.66.0,10.16.67.0,10.16.68.0, 10.16.64.0/24,ABC,Prod,10.16.64.0,10.16.65.0,10.16.66.0,10.16.67.0,10.16.68.0,10.16.69.0, 10.16.64.0/24,ABC,Prod,10.16.64.0,10.16.65.0,10.16.66.0,10.16.67.0,10.16.68.0,10.16.69.0,10.16.70.0, 10.16.64.0/24,ABC,Prod,10.16.64.0,10.16.65.0,10.16.66.0,10.16.67.0,10.16.68.0,10.16.69.0,10.16.70.0,10.16.71.0,

    The following S/R, with search mode = Regular expression, will realize everything, after clicking, ONCE only, on the Replace All button !!

    SEARCH = (.*?,.*?,.*?,)(?:(.*?),)?(?:(.*?),)?(?:(.*?),)?(?:(.*?),)?(?:(.*?),)?(?:(.*?),)?(?:(.*?),)?(?:(.*?),)?

    REPLACE = \1(?2\2)\r\n(?3\1\3\r\n)(?4\1\4\r\n)(?5\1\5\r\n)(?6\1\6\r\n)(?7\1\7\r\n)(?8\1\8\r\n)(?9\1\9\r\n)

    So, in one go, the resulting text would be :

    10.16.64.0/24,ABC,Prod, 10.16.64.0/24,ABC,Prod,10.16.64.0 10.16.64.0/24,ABC,Prod,10.16.64.0 10.16.64.0/24,ABC,Prod,10.16.65.0 10.16.64.0/24,ABC,Prod,10.16.64.0 10.16.64.0/24,ABC,Prod,10.16.65.0 10.16.64.0/24,ABC,Prod,10.16.66.0 10.16.64.0/24,ABC,Prod,10.16.64.0 10.16.64.0/24,ABC,Prod,10.16.65.0 10.16.64.0/24,ABC,Prod,10.16.66.0 10.16.64.0/24,ABC,Prod,10.16.67.0 10.16.64.0/24,ABC,Prod,10.16.64.0 10.16.64.0/24,ABC,Prod,10.16.65.0 10.16.64.0/24,ABC,Prod,10.16.66.0 10.16.64.0/24,ABC,Prod,10.16.67.0 10.16.64.0/24,ABC,Prod,10.16.68.0 10.16.64.0/24,ABC,Prod,10.16.64.0 10.16.64.0/24,ABC,Prod,10.16.65.0 10.16.64.0/24,ABC,Prod,10.16.66.0 10.16.64.0/24,ABC,Prod,10.16.67.0 10.16.64.0/24,ABC,Prod,10.16.68.0 10.16.64.0/24,ABC,Prod,10.16.69.0 10.16.64.0/24,ABC,Prod,10.16.64.0 10.16.64.0/24,ABC,Prod,10.16.65.0 10.16.64.0/24,ABC,Prod,10.16.66.0 10.16.64.0/24,ABC,Prod,10.16.67.0 10.16.64.0/24,ABC,Prod,10.16.68.0 10.16.64.0/24,ABC,Prod,10.16.69.0 10.16.64.0/24,ABC,Prod,10.16.70.0 10.16.64.0/24,ABC,Prod,10.16.64.0 10.16.64.0/24,ABC,Prod,10.16.65.0 10.16.64.0/24,ABC,Prod,10.16.66.0 10.16.64.0/24,ABC,Prod,10.16.67.0 10.16.64.0/24,ABC,Prod,10.16.68.0 10.16.64.0/24,ABC,Prod,10.16.69.0 10.16.64.0/24,ABC,Prod,10.16.70.0 10.16.64.0/24,ABC,Prod,10.16.71.0

    Et voilà ! Well, although I practised regexes, since many years, I, always, surprised by their incredible power !!

    Notes :

    If the original line is only 10.16.64.0/24,ABC,Prod,, without any address, after, the S/R just rewrites that line

    In the search regex, the 8 parts (.*?) are groups from 2 to 9, each containing a possible address, which must be rewritten, in replacement

    These 8 groups, followed by a comma, are embedded in an optional non-capturing group (?:(.*?),)? ( the group may be present [1] or absent [0] )

    At the beginning, the part (.*?,.*?,.*?,) looks for the first three fields : network, datacenter and environment, followed by a comma

    In replacement, the syntax (?#\1\#\r\n) is called a conditional replacement. It means that IF the group # exists, then it rewrites the group 1, followed by the group #, followed by the Windows EOL characters \r\n

    At the beginning, the part \1(?2\2)\r\n writes, first, the group 1. Then it writes the group 2, ONLY IF it exists ( the first IPV4 address ), and, finally rewrites the Windows EOL characters \r\n

    Remarks :

    Contrary to my previous post, with this new S/R, there is no condition, any more, about the contents of fields 2 and 3 ! They could be, for instance : 10.16.64.0/24,99999,00000000,… :-)

    Any possible leading indentation, of a line, is just kept, by this S/R !

    You can click, either, on the Replace All button AND/OR on the Replace button, for a step by step replacement :-)

    Cheers,

    guy038