A case study of regular expression usage in batch processing findstr _dos/bat

Source: Internet
Author: User
1.findstr. 2.txt or Findstr "." 2.txt
Find any character from file 2.txt, excluding null characters or blank lines

2.findstr. * 2.txt or findstr ". *" 2.txt
Find any character from file 2.txt including blank lines and null characters

3.findstr "[0-9]" 2.txt
Find a string or row that includes the number 0-9 from file 2.txt

4.findstr "[A-za-z]" 2.txt
Find a string or row that includes any character from file 2.txt

5.findstr "[Abcezy]" 2.txt
Find a string or line that includes a b c e z y letter from File 2.txt

6.findstr "[A-fl-z]" 2.txt
Finds the lowercase character a-f l-z string from file 2.txt, but does not contain the letters G H I J K.

7.findstr "M[abc][hig]y" 2.txt
From the file 2.txt can match Mahy, Mbiy, Mahy, etc. .....

8. ^ and $ application of symbols
^ Represents the beginning of the line, and "^step" matches only the first word in "Step Hello World"
$ indicates line end, "step$" matches only the last word in "Hello World"

9.finstr "[^0-9]" 2.txt
If it is a string of pure numbers or a line filtered out, such as 2323423423 string, if it is 345hh888 such a form will not be.

10.findstr "[^a-z]" 2.txt
Ditto, if the string or line of pure letters filtered out, such as sdlfjlkjlksjdklfjlskdf characters, if it is sdfksjdkf99999 such a form, doped with numbers will not be

The role of 11.* number
As mentioned earlier, ". *" means that the search condition is any character, the * number is not in the regular expression of any character, but the left character or the number of repetitions of the expression, * the number of repetitions is 0 or more times.

12.findstr "^[0-9]*$" 2.txt
This is a match to find the pure number, such as 234234234234, if it is 2133234kkjl234 is filtered out.
Findstr "^[a-z]*$" 2.txt
This is a match to find the pure letter, such as SDFSDFSDFSDF, if it is 213sldjfkljsdlk is filtered out
If there are no * numbers in the search terms, that is, do not repeat the search conditions on the left, that is, [0-9] [A-z] that can only match the first character of the string and only this one character, because there is the beginning and end of the limit, "^[0-9]$" the first character if the number is matched, if not filtered out, If the string is 9 match, if it is 98 or 9j and so on is not OK.

The role of the expression "\<...\>"
This representation precisely looks for a string, \<sss the beginning position of the word,sss\> the end position of the word
echo Hello World computer|findstr "\<computer\>" in this form
echo Hello worldcomputer|findstr "\<computer\>" is not the form, he is looking for "computer" this string, so not.
echo Hello worldcomputer|findstr ".*computer\>" so you can match it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.