• 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

  • Sorting "Folded Blocks" or "Colapsed Level 1"

    6
    0 Votes
    6 Posts
    4k Views
    Jim DaileyJ

    Back in the day we used to have flame wars over which editor was the only one worth using. Now that all right-thinking people have settled on Notepad++, I guess we can spar over the best scripting language! :-)

    Well, we could if I was of a mind to (and believe me, 25 years ago or so I would have been), but I don’t have the time or desire to care about the details any more. :-)

  • How multiply run macros without multiply run window, till end

    Locked
    1
    0 Votes
    1 Posts
    1k Views
    No one has replied
  • Sorting a Text File from certain Columns

    Locked
    2
    1 Votes
    2 Posts
    12k Views
    Scott SumnerS

    The TextFX plugin may help you.

    See the TextFX menu -> TextFX Tools -> Sort lines case sensitive (at column)
    for example.

    What you do is make a column block (Alt + Left-click, then drag) covering the lines you want sorted and have the left side of the block be in the first column you want the sort to be based upon.

  • Version 6.8.4 breaks JSLint plugin

    15
    0 Votes
    15 Posts
    12k Views
    Per SidénP

    @Manuel-Lemcke it was promising that a new version was released, but unfortunately it fails on any JSLint option and there have been no updates since. Version 0.8.1.117 distributed with Notepad++ is still the better option.

    I advice against Notepad++ distributing 0.8.3.

  • creating a form

    Locked
    4
    0 Votes
    4 Posts
    7k Views
    dailD

    As others have pointed out it isn’t natively supported out of the box.

    That being said it is kind of possible to do what you want with a plugin and/or script. You’d have to write a custom lexer to determine which parts are meant to be locked (depending on the format this may be very easy or complex). Specific Scintilla styles can be “locked”, though supposedly not perfect. The custom lexer could mark and color parts of the form as being locked vs unlocked.

  • CSS language with @media

    Locked
    1
    0 Votes
    1 Posts
    1k Views
    No one has replied
  • Regex: Insert new line at the beginning of file

    Locked
    6
    1 Votes
    6 Posts
    8k Views
    Vasile CarausV

    Notepad with Regex is much easy to use, for me, which I am not a programmer. And, I believe, there are many people like me… Not everyone is a programmer.

  • Regex: Select only the line 27 (mark a particular line)

    Locked
    11
    0 Votes
    11 Posts
    5k Views
    guy038G

    Hi Vasile Caraus,

    Just see my solution, below, in topic about replacing by multiple values of a same line :

    https://notepad-plus-plus.org/community/topic/12341/regex-double-your-words/9

    Cheers,

    guy038

  • Automatically add space to end of line

    Locked
    6
    0 Votes
    6 Posts
    4k Views
    Scott SumnerS

    It works because the Alt+Lclick is really starting a column-block, just no drag while holding Alt down to define that block. Column-blocking, out of necessity, needs to work with virtual spacing as some lines that may be in the column block might be shorter than others.

    I don’t turn on permanently the beyond end-of-line movement modification as guy038 describes, because I found that that causes some strange behavior with auto-indentation in the language I typically use most often (Python). Actually, I do have a pythonscript tied to a keypress that toggles cursor end-of-line “freedom” mode on and off for when I want it.

  • Modifying police size

    Locked
    5
    0 Votes
    5 Posts
    3k Views
    MAPJe71M

    Thanks!

  • Delete spelling suggestions

    Locked
    2
    0 Votes
    2 Posts
    2k Views
    Scott SumnerS

    Go to the Settings dropdown menu.
    Choose Preferences…
    In the box on the left, select “Auto-Completion”
    Disable (uncheck) choices on the right until you are happy with the result.

  • What this regex doing?

    Locked
    3
    0 Votes
    3 Posts
    3k Views
    guy038G

    Hello Vasile Caraus,

    In replacement regex, the contents of a nth subset of parentheses, defining a group, in the search regex, may be written in THREE different ways :

    From \1 to \9 So, this syntax is acceptable if you don’t have more than 9 capturing groups, in the search regex

    From $0 to $N In the syntax $N N may be a number, greater than 10. I didn’t try it, but I suppose that N can be up to 65535 !!. Just note that $0 represents the totality of the match, whereas $1 stands for group 1, $2 stands for group 2 and so on…

    From ${0} to ${N}, with the SAME syntax as above. This said, what is the interest to surround the number by curly braces ? Do you guess it…

    Well just imagine that you want, for instance, to rewrite, in replacement, the contents of group1, but preceded and followed by the string 999. At first sight, you would simply write 999$1999. However, after replacement, you just obtain the string 999 !
    Because the regex engine thinks that you want to write the literal string 999, followed by the contents of group $1999. As, of course, this group does not exists in the search regex, it just replace the non-defined group $1999 by an empty string !

    Therefore, the solution consists to use the third and right syntax, giving the replacement regex 999${1}999

    So, Vasile Caraus, when you write $1\2, in replacement ( or also $1$2, \1$2 or \1\2 ) as you didn’t define a second group, in the search regex, this is just equivalent to the simple \1 or $1 syntax.

    And, as the group 1 (.+) represents all the standard characters of a NON-empty line, between the two assertions Beginning and End of line, you just replace any line by itself !!

    Then, it’s obvious that hitting CTRL-Z cancels each S/R, giving back the identical original lines :-))

    Best Regards,

    guy38

  • Irregular BOM Code in text file triggers font change

    Locked
    1
    0 Votes
    1 Posts
    1k Views
    No one has replied
  • Where are View Menu Hide Margin toggles stored?

    Locked
    1
    0 Votes
    1 Posts
    2k Views
    No one has replied
  • pound character is using double byte C2A3 instead of single byte A3

    Locked
    4
    0 Votes
    4 Posts
    3k Views
    Claudia FrankC

    @Harishkumar-Pathangay

    In HEX Editor Mode, why it is converting to Unicode?

    this plugin was written back in 2009 and at this time npp didn’t support
    encodings like today, only the standard ansi, utf-8 … were available.

    Cheers
    Claudia

  • Curl Error when trying to update?

    Locked
    1
    0 Votes
    1 Posts
    2k Views
    No one has replied
  • 0 Votes
    1 Posts
    1k Views
    No one has replied