How to mark lines with under "x" characters after : in a line.



  • I am working on sorting a list of my login information.

    My website requires a password of 8 characters, so I want to remove the lines with 7 or less characters after the : divider between the email/password.

    I am just unsure of how to do this, help is appreciated. :)

    Example of lines I want to keep:

    mystictoffee11@yahoo.com:smartguy
    maniactor2313@yahoo.com:maurermartin

    Examples of lines I want to delete:

    philipsedf3@yahoo.com:plakes9
    genciyev13@mail.ru:241241



  • @Nicholas-Wetzel: Welcome to the Notepad++ Community.

    Example of lines I want to keep:
    Example of lines I want to delete:

    Thank you for clearly specifying both. That helps us help you.

    Using the regex ^.*:.{1,7}(\R+|\z) to find, with replace being empty, should delete those lines



  • @Nicholas-Wetzel

    i hope your example data does not contain real email addresses and real passwords, as you have just published them to the public. 😉



  • Please, how do I delete two lines that start with the same word, in multiple files.
    example:
    ADDRESS: aaaaaaaaaaaaaa
    ADDRESS-CITY: bbbbbbbbb



  • @Francisco

    from your given example I would say
    find what:^ADDRESS.*$ and leave replace with empty.
    BUT this assumes that the word ADDRESS REALLY starts from the line,
    meaning there is no space or tab or whatever special char in front of ADDRESS.

    MAKE YOUR BACKUP and then run it, slightly modifications might erase your whole file.



  • @Ekopalypse said:

    find what:^ADDRESS.*$ and leave replace with empty.

    That leaves a blank line for each deleted line. If @Francisco wants the whole line, including newline, to be deleted, then the from what: could be ^ADDRESS.*(\R|\Z)



  • @PeterJones said:

    ^ADDRESS.*(\R|\Z)

    I have a problem, the selection starts on the first line that contains the word ^ ADDRESS. * (\ R | \ Z) and ends on the last line of the file, selecting the other lines that do not start with ^ ADDRESS. Z)



  • @Francisco

    If you want to stay on the same line, lead off the search expression with (?-s). This tells the searcher to not allow a . used later to match a line ending character(s). Thus the .* part won’t spillover match onto multiple lines.



  • @Alan Kilborn, thanks, good morning everyone, I was successful using ADDRESS (? - s), selecting only the lines that start with ADDRESS. To exclude them, mark all and exclude the marked lines.
    Is it possible to perform this operation on all open files? I can only find, I can not mark them



  • @Francisco

    You are correct; you cannot bookmark more than one file per marking operation.

    It isn’t clear to me what your real goal is exactly but it appears to be a deletion operation. I think it is likely that this can be done totally with a regular expression replacement and not a combo of regex marking followed by boomarked lines manipulation.



  • @Alan-Kilborn thanks…
    What I need:
    I have 100 text files, with the same format, each with several lines.
    6 of these lines, are present in all files and start like this:
    ADDRESS:
    ADDRESS-CITY: Christmas
    ADDRESS-STATE-PROVINCE: RN
    ADDRESS-POSTALCODE: 59054550
    ADDRESS-COUNTRY: BRAZIL
    EMAIL: mjnhx@globo.com
    I need to easily delete the 6 lines above.



  • @Francisco said:

    I have 100 text files, with the same format, each with several lines.
    6 of these lines, are present in all files and start like this:

    The problem is, you’ve already rejected our solutions (or, at least, you keep on asking, so we have to assume your problem isn’t solved), but have shown nothing that indicates why what we’ve given doesn’t work for you. One reason for this is explained in my boilerplate below (after the dashed line).

    That said, maybe you’re just unsure how to combine @Alan-Kilborn’s fix to my regex, and then have it actually do the deletion, rather than just highlighting. If that’s the case, then it’s simple. I’ll also tweak my portion, because you have now indicated that it should also delete EMAIL, which wasn’t anywhere in your original problem statement.

    • Find What: (?-s)^(?:ADDRESS(-.*?)*|EMAIL):.*?(?:\R|\Z)
      • (?-s): don’t have . match newline
      • ^: match starts at beginning of line
      • (?:...): make a group, but don’t give it a number
      • ADDRESS(-.*?)*: match the word “ADDRESS”, possibly followed by one or more hyphens, possibly followed by other characters
      • |: the OR operator – will match what is before or what is after
      • EMAIL: the word EMAIL
      • :: that group of ADDRESS or EMAIL must be immediately followed by a colon to match
      • .*?: match the remaining characters on the line
      • (?:\R|\Z): another unnumbered group, this time containing a NEWLINE sequence (\R = CR, LF, or CRLF) or end-of-file (\Z).
    • Replace With: empty
      • this will delete the whole line matched above, including the newline
    • Mode = regular expression

    I recommend getting the expression working with one file; once that works, then you can move on to using the Find in Files for all your files.

    With those settings, this block of text:

    ADDRESS:
    ADDRESS-CITY: Christmas
    ADDRESS-STATE-PROVINCE: RN
    ADDRESS-POSTALCODE: 59054550
    ADDRESS-COUNTRY: BRAZIL
    EMAIL: mjnhx@globo.com
    You tell us nothing about the remainder of the file, so I don't know whether
    the following lines match your pattern, or whether they don't:
    SOMETHING-ELSE: value
    MORE-COLONED-LINES: here
    For now, I'll assume you want to keep everything except lines that 
    start with "ADDRESS...:" or "EMAIL:"
    

    would be edited to:

    You tell us nothing about the remainder of the file, so I don't know whether
    the following lines match your pattern, or whether they don't:
    SOMETHING-ELSE: value
    MORE-COLONED-LINES: here
    For now, I'll assume you want to keep everything except lines that 
    start with "ADDRESS...:" or "EMAIL:"
    

    Of course, this is still making lots of assumptions. Other possible interpretations are that you want the first six lines of any file to be deleted, whatever the text. And it might be that the “SOMETHING-ELSE:” I indicated in the example text might also be “ADDRESS:”, in which case we’d have to tweak my regex to limit those matches to the first lines of a file, because mine assumes that any lines starting with “ADDRESS…:” or “EMAIL:” will be deleted.

    It would be easier to help you if you’d give all the information we need at once, rather than doling it out piecemeal. As explained below, a good example would have examples of lines to match and lines not to match, and would show us both the before and after. A good example will also be properly formatted using Markdown (like my example was) – links to Markdown help and regex help are in the boilerplate below.

    -----
    FYI: I often add this to my response in regex threads, unless I am sure the original poster has seen it before. Here is some helpful information for finding out more about regular expressions, and for formatting posts in this forum (especially quoting data) so that we can fully understand what you’re trying to ask:

    This forum is formatted using Markdown, with a help link buried on the little grey ? in the COMPOSE window/pane when writing your post. For more about how to use Markdown in this forum, please see @Scott-Sumner’s post in the “how to markdown code on this forum” topic, and my updates near the end. It is very important that you use these formatting tips – using single backtick marks around small snippets, and using code-quoting for pasting multiple lines from your example data files – because otherwise, the forum will change normal quotes ("") to curly “smart” quotes (“”), will change hyphens to dashes, will sometimes hide asterisks (or if your text is c:\folder\*.txt, it will show up as c:\folder*.txt, missing the backslash). If you want to clearly communicate your text data to us, you need to properly format it.

    If you have further search-and-replace (“matching”, “marking”, “bookmarking”, regular expression, “regex”) needs, study this FAQ and the documentation it points to. Before asking a new regex question, understand that for future requests, many of us will expect you to show what data you have (exactly), what data you want (exactly), what regex you already tried (to show that you’re showing effort), why you thought that regex would work (to prove it wasn’t just something randomly typed), and what data you’re getting with an explanation of why that result is wrong. When you show that effort, you’ll see us bend over backward to get things working for you. If you need help formatting, see the paragraph above.

    Please note that for all regex and related queries, it is best if you are explicit about what needs to match, and what shouldn’t match, and have multiple examples of both in your example dataset. Often, what shouldn’t match helps define the regular expression as much or more than what should match.



  • @PeterJones said:

    (?-s)^(?:ADDRESS(-.?)|EMAIL):.*?(?:\R|\Z)

    (? -s) ^ (?: ADDRESS (-. *?) * | EMAIL):. *? (?: \ R | \ Z)
    This command worked perfectly on all files in a given folder. All lines started by ADDRESS and EMAIL were automatically deleted as desired.
    I am very pleased and grateful for this important help.
    Only three files did not have their email deleted, because the email line does not have the word EMAIL at the beginning of the line.
    P.S. I do not know if it would be possible in this command to include the search for any line that contains the @



  • @PeterJones said:

    @Nicholas-Wetzel: Welcome to the Notepad++ Community.

    Example of lines I want to keep:
    Example of lines I want to delete:

    Thank you for clearly specifying both. That helps us help you.

    Using the regex ^.*:.{1,7}(\R+|\z) to find, with replace being empty, should delete those lines

    Mind checking my new thread here please?

    https://notepad-plus-plus.org/community/topic/18149/sorting-login-information


Log in to reply