How to remove lines that do not have both lowercase and uppercase Latin letters and numbers (special characters, such as quotes, commas or question marks, do not matter), as well as all those whose length is less than 8.

For example, the following lines will be deleted:

jkjhuih67,2 23jfkcm5 ,.,kj8f83 86758493 38tfgDE iiiiiiiiiiii4 ,.,.,...,,.,.,@ 

However, these will not be deleted:

 jkkJUISD7fgffb ,,,,cHDYU3.,gfgtr 7843834UsDSDs ddddDfdiuy788 DDDDDdfdD4545TTGF 
  • [a-zA-Z0-9]{8} ? - gil9red
  • I did not understand the condition "only from lowercase Latin letters OR / AND numbers OR characters, also all, whose length is less than 8 characters.". What does OR / AND NUMBERS OR characters mean? - cpp questions
  • "This means that any line containing less than 8 characters will be deleted." The "ddddD" is not removed in the example - cpp questions
  • I apologize. Edited - yan dashkov
  • Only those lines are saved in which the numbers are combined with uppercase and lowercase letters (characters can be added) whose length is at least 8 characters. - yan dashkov

1 answer 1

Use the following expression to capture the desired lines:

 /^(?=.*[az])(?=.*[AZ])(?=.*\d)(?=.*[@#$%^&+=]?).{8,}/m 

Note that the i flag should not be used, only m .

See the regular expression demo .

Since I do not have a Notepad, I will use the example of Sublime Text. It is permissible to use a negative lookahead assertion with this expression by changing the regular expression to the following form:

 (?!(^(?=.*[az])(?=.*[AZ])(?=.*\d)(?=.*[@#$%^&+=]?).{8,}))^.+$ 

enter image description here

And make a simple replacement for the void to remove these unnecessary lines.

PS My version is not considered perfect, but it seems like it works.

  • Alas, your algorithm does not work. He does not find strings of the form asdfghjkl1, although they do not meet the criteria: no capital Latin letters. - yan dashkov
  • @yandashkov, I think this is case sensitive, try to manipulate it .. Read more . - Let's say Pie
  • @yandashkov, in Sublime Text, everything works fine when the case sensitive (ALT + C) parameter is enabled. - Let's say Pie
  • Are there any programs that can do this with a simpler script? I do not know what kind of manipulation to do: the script looks complicated. - yan dashkov
  • @yandashkov, just see the solution here at stackoverflow.com/questions/43547201/… - Let's say Pie