Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

The basic usage of FINDSTR regular expressions


May 23, 2021 DOS Command learning manual



9527 Finishing



The basic usage of FINDSTR regular expressions


1.findstr . 2 .txt or Findstr "." 2 .txt

Look for any .txt file 2, not empty characters or empty lines

====================



2.findstr . . . 2.txt or findstr "." 2.txt

Find any character .txt file 2, including empty lines and empty characters

====================



3.findstr "[0-9]" 2.txt

Look for strings .txt lines that include the number 0-9 from file 2

====================



4.findstr "[a-zA-Z]" 2.txt

Find a string .txt line that includes any character from file 2

====================



5.findstr "[abcezy]" 2.txt

Look for strings .txt a b c e z y letter from file 2

====================



6.findstr "[a-fl-z]" 2.txt

Look for strings .txt the lowercase character a-f l-z from file 2, but do not contain the letters g h I j k.

====================



7.findstr "M[abc][hig]Y" 2.txt

From file 2.txt can match MahY, MbiY, MahY, etc....

====================



8. The application of the symbols . . . and $

At the top of the line, the word "step" matches only the first word in "step hello world"

$ represents the end of the line, and "step$" matches only the last word in "hello world step"

====================



9.finstr "[^0-9]" 2.txt

If it's a string of pure numbers or a line filtered out, such as a string like 2323423423, if it's a 345hh88 form, it's not.

====================



10.findstr "[^a-z]" 2.txt

Similarly, if it is a string or line of pure letters filtered out, such as sdlfjlksjlksjdklskdf characters, if it is a form like sdfksjdkf99999, doped with numbers is not

====================



The role of the number 11

As already said earlier, "."" indicates that the condition of the search is arbitrary character, and that the character's role in the regular expression is not any character, but rather the number of repetitions of the left character or expression, and that the number of repetitions is zero or more.

====================



12.findstr "^[0-9]*$" 2.txt

This is a match found pure number, for example 234234234234, if it is 2133234kkjl234 is filtered out.

Findstr "^[a-z]*$" 2.txt

This is a match found in pure letters, such as sdfsdfsdfsdf, if it is 213sldjfkljsdlk is filtered out

If there is no number in the search criteria, that is to say, the search criterion on the left is not repeated, that is, the first character of the string can only be matched, because there is a limit on the beginning and end of the line, "the first character is matched if it is a number, if it is not filtered, if the string is 9, if it is 98 or 9j and so on can not be.

=====================



13. The effect of this expression

This represents an exact look for a string, with the beginning of the word and the end of the word represented by sss

Echo hello world | the form of "findstr"

Echo hello worldcomputer |findstr" is not the form, he is looking for the "computer" string, so can not.

echo hello worldcomputer |findstr"

=====================