China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-02 20:31
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Question about how to use findstr character class expressions View 1,128 Replies 6
Original Poster Posted 2006-12-25 23:28 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
findstr /r /m ".txt"

When I want to search all text files in the current directory for files that contain Chinese characters (double-byte characters), how should be expressed??

[ Last edited by namejm on 2006-12-25 at 12:57 PM ]
Floor 2 Posted 2006-12-25 23:38 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
   is that what you want to search for? Or do you want to search for all Chinese characters?
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 3 Posted 2006-12-25 23:40 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
All Chinese characters
Floor 4 Posted 2006-12-26 01:11 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Could an expert please give me some advice, mail:everest79@163.com
Floor 5 Posted 2006-12-26 02:04 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
  findstr doesn't have a regex specifically for matching Chinese characters yet, so it's rather troublesome.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 6 Posted 2006-12-26 02:55 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Could namejm give an example of a class expression? Is it used by the name of a character set?
Floor 7 Posted 2006-12-26 04:57 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
  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
RaterScoreTime
everest79 +2 2006-12-26 08:03
lxmxn +4 2008-03-06 23:23
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Forum Jump: