I once posted this article before, the basic usage of FINDSTR regular expressions as organized by brother 9527. I can't find that post right now, so I'm posting it again:
Basic usage of FINDSTR regular expressions
1.findstr . 2.txt 或 Findstr "." 2.txt
Search any character in file 2.txt, excluding null characters or blank lines
====================
2.findstr .* 2.txt 或 findstr ".*" 2.txt
Search any character in file 2.txt, including blank lines and null characters
====================
3.findstr "" 2.txt
Search strings or lines in file 2.txt that include digits 0-9
====================
4.findstr "" 2.txt
Search strings or lines in file 2.txt that include any letters
====================
5.findstr "" 2.txt
Search strings or lines in file 2.txt that include the letters a b c e z y
====================
6.findstr "" 2.txt
Search strings of lowercase characters a-f l-z in file 2.txt, but not the letters g h I j k.
====================
7.findstr "MY" 2.txt
In file 2.txt it can match MahY, MbiY, MahY, etc…..
====================
8. Application of the ^ and $ symbols
^ indicates the start of a line; "^step" matches only the first word in "step hello world"
$ indicates the end of a line; "step$" matches only the last word in "hello world step"
====================
9.finstr "" 2.txt
If it is a pure numeric string or line, it gets filtered out, for example a string like 2323423423. But a form like 345hh888 won't do.
====================
10.findstr "" 2.txt
Same as above. If it is a pure alphabetic string or line, it gets filtered out, for example characters like sdlfjlkjlksjdklfjlskdf. But a form like sdfksjdkf99999, mixed with digits, won't do
====================
11.The role of the * sign
This was already mentioned above: ".*" means the search condition is any character. The role of * in a regular expression is not "any character", but the number of repetitions of the character or expression on the left. * means the number of repetitions is zero or more.
====================
12.findstr "^*$" 2.txt
This matches pure numbers that are found, for example 234234234234. If it is 2133234kkjl234 then it gets filtered out.
Findstr "^*$" 2.txt
This matches pure letters that are found, for example sdfsdfsdfsdf. If it is 213sldjfkljsdlk then it gets filtered out
If there is no * in the search condition, that is, the search condition on the left is not repeated, in other words , then it can only match the first character of the string and only that one character, because of the restriction of start-of-line and end-of-line. With "^$", if the first character is a digit then it matches, if not then it is filtered out. If the string is 9 then it matches, but if it is 98 or 9j or the like then it won't work.
=====================
13. The role of the "\<…\>" expression
This means an exact search for a string. \<sss means the starting position of a word, and sss\> means the ending position of a word
echo hello world computer|findstr "\<computer\>" in this form
echo hello worldcomputer|findstr "\<computer\>" in this form won't do. What it is looking for is the string "computer", so it won't work.
echo hello worldcomputer|findstr ".*computer\>" this way it can match
=====================
Recent Ratings for This Post
( 2 in total)
Click for details
| Rater | Score | Time |
| everest79 |
+2 |
2006-12-26 08:03 |
| lxmxn |
+4 |
2008-03-06 23:23 |
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。