Here is the translation of the above content:
Post a section of the usage of findstr. The original poster can imitate to write a code to restrict the input type:
Basic Usage of FINDSTR Regular Expressions
1. findstr . 2.txt or Findstr "." 2.txt
Find any characters from file 2.txt, excluding empty characters or blank lines
====================
2. findstr .* 2.txt or findstr ".*" 2.txt
Find any characters from file 2.txt including blank lines and empty characters
====================
3. findstr "" 2.txt
Find strings or lines including numbers 0-9 from file 2.txt
====================
4. findstr "" 2.txt
Find strings or lines including any characters from file 2.txt
====================
5. findstr "" 2.txt
Find strings or lines including letters a, b, c, e, z, y from file 2.txt
====================
6. findstr "" 2.txt
Find strings of lowercase characters a-f and l-z from file 2.txt, but do not include letters g, h, I, j, k.
====================
7. findstr "MY" 2.txt
Can match MahY, MbiY, MahY, etc. in file 2.txt…..
====================
8. Application of ^ and $ symbols
^ means the beginning of a line, " ^step" only matches the first word in "step hello world"
$ means the end of a line, "step$" only matches the last word in "hello world step"
====================
9. finstr "" 2.txt
If it is a pure digital string or line, filter it out. For example, a string like 2323423423, if it is in the form of 345hh888, it is not.
====================
10. findstr "" 2.txt
Same as above, if it is a pure letter string or line, filter it out. For example, a character like sdlfjlkjlksjdklfjlskdf, if it is in the form of sdfksjdkf99999, mixed with numbers, it is not.
====================
11. Role of * symbol
As mentioned earlier, ".*" means the search condition is any character. The role of * in regular expressions is not any character, but means the number of repetitions of the left character or expression. * means the number of repetitions is zero or more times.
====================
12. findstr "^*$" 2.txt
This matches pure numbers found, for example 234234234234, if it is 2133234kkjl234, it is filtered out.
Findstr "^*$" 2.txt
This matches pure letters found, for example sdfsdfsdfsdf, if it is 213sldjfkljsdlk, it is filtered out.
If there is no * sign in the search condition, that is, not repeating the left search condition, that is, , it can only match the first character of the string and only this character. Because of the restrictions of the beginning and end of the line, "^$" will match if the first character is a number, and filter out if it is not. If the string is 9, it matches; if it is 98 or 9j, etc., it is not possible.
=====================
13. The role of "\<…\>" expression
This means to accurately find a string. \<sss means the start position of a word, and sss\> means the end position of a word.
echo hello world computer|findstr "\<computer\>" such form
echo hello worldcomputer|findstr "\<computer\>" such form is not, it wants to find the string "computer", so it is not.
echo hello worldcomputer|findstr ".*computer\>" this can match
=====================