为什么findstr不能正确处理案例(在某些情况下)?

时间:2021-04-25 02:08:06

While writing some recent scripts in cmd.exe, I had a need to use findstr with regular expressions - customer required standard cmd.exe commands (no GnuWin32 nor Cygwin nor VBS nor Powershell).

在cmd中写一些最近的脚本。exe,我需要使用findstr与正则表达式——客户要求的标准cmd。exe命令(无GnuWin32或Cygwin、VBS或Powershell)。

I just wanted to know if a variable contained any upper-case characters and attempted to use:

我只是想知道一个变量是否包含任何大写字符并试图使用:

> set myvar=abc
> echo %myvar%|findstr /r "[A-Z]"
abc
> echo %errorlevel%
0

When %myvar% is set to abc, that actually outputs the string and sets errorlevel to 0, saying that a match was found.

当将%myvar%设置为abc时,它实际上输出字符串并将errorlevel设置为0,表示找到了匹配项。

However, the full-list variant:

然而,完整列表变体:

> echo %myvar%|findstr /r "[ABCDEFGHIJKLMNOPQRSTUVWXYZ]"
> echo %errorlevel%
1

does not output the line and it correctly sets errorlevel to 1.

不输出行并正确地将errorlevel设置为1。

In addition:

此外:

> echo %myvar%|findstr /r "^[A-Z]*$"
> echo %errorlevel%
1

also works as expected.

也像预期的那样工作。

I'm obviously missing something here even if it's only the fact that findstr is somehow broken.

很明显,我在这里漏掉了什么,即使只是findstr被破坏了。

Why does the first (range) regex not work in this case?

为什么在这种情况下,第一个(范围)regex不工作?


And yet more weirdness:

然而,更不可思议:

> echo %myvar%|findstr /r "[A-Z]"
abc
> echo %myvar%|findstr /r "[A-Z][A-Z]"
abc
> echo %myvar%|findstr /r "[A-Z][A-Z][A-Z]"
> echo %myvar%|findstr /r "[A]"

The last two above also does not output the string!!

上面的最后两个也没有输出字符串!!

4 个解决方案

#1


14  

I believe this is mostly a horrible design flaw.

我认为这主要是一个可怕的设计缺陷。

We all expect the ranges to collate based on the ASCII code value. But they don't - instead the ranges are based on a collation sequence that nearly matches the default sequence used by SORT. EDIT -The exact collation sequence used by FINDSTR is now available at https://*.com/a/20159191/1012053 under the section titled Regex character class ranges [x-y].

我们都希望基于ASCII码值的范围进行排序。但它们没有——相反,这些范围是基于排序序列,几乎与排序所使用的默认序列相匹配。编辑—FINDSTR所使用的精确排序序列现在可以在https://*.com/a/20159191/1012053中使用,它的标题是Regex字符类范围[x-y]。

I prepared a text file containing one line for each extended ASCII character from 1 - 255, excluding 10 (LF), 13 (CR), and 26 (EOF on Windows). On each line I have the character, followed by a space, followed by the decimal code for the character. I then ran the file through SORT and captured the output in a sortedChars.txt file.

我编写了一个文本文件,其中包含了从1 - 255,不包括10 (LF), 13 (CR),和26 (EOF在Windows上)的每个扩展ASCII字符的一行。在每一行上,我都有字符,然后是空格,然后是字符的十进制代码。然后,我通过排序运行该文件,并在一个sortedChars中捕获输出。txt文件。

I now can easily test any regex range against this sorted file and demonstrate how the range is determined by a collation sequence that is nearly the same as SORT.

现在,我可以轻松地对这个已排序的文件进行任何regex范围的测试,并演示如何使用几乎与排序相同的排序序列来确定范围。

>findstr /nrc:"^[0-9]" sortedChars.txt
137:0 048
138:½ 171
139:¼ 172
140:1 049
141:2 050
142:² 253
143:3 051
144:4 052
145:5 053
146:6 054
147:7 055
148:8 056
149:9 057

The results are not quite what we expected in that chars 171, 172 and 253 are thrown in the mix. But the results make perfect sense. The line number prefix corresponds to the SORT collation sequence, and you can see that the range exactly matches according to the SORT sequence.

结果并不是我们所期望的,在这张图表中,有171、172和253。但结果是完全合理的。行号前缀对应排序排序序列,您可以看到按排序顺序匹配的范围。

Here is another range test that exactly follows the SORT sequence:

下面是另一种范围测试,它完全遵循排序顺序:

>findstr /nrc:"^[!-=]" sortedChars.txt
34:! 033
35:" 034
36:# 035
37:$ 036
38:% 037
39:& 038
40:( 040
41:) 041
42:* 042
43:, 044
44:. 046
45:/ 047
46:: 058
47:; 059
48:? 063
49:@ 064
50:[ 091
51:\ 092
52:] 093
53:^ 094
54:_ 095
55:` 096
56:{ 123
57:| 124
58:} 125
59:~ 126
60:¡ 173
61:¿ 168
62:¢ 155
63:£ 156
64:¥ 157
65:₧ 158
66:+ 043
67:∙ 249
68:< 060
69:= 061

There is one small anomaly with alpha characters. Character "a" sorts between "A" and "Z" yet it does not match [A-Z]. "z" sorts after "Z", yet it matches [A-Z]. There is a corresponding problem with [a-z]. "A" sorts before "a", yet it matches [a-z]. "Z" sorts between "a" and "z", yet it does not match [a-z].

有一个小的异常与字母的字符。“a”和“Z”之间的“a”类型,但并不匹配。“z”排序后“z”,但它匹配[A-Z]。[a-z]有一个相应的问题。“A”在“A”之前排序,但它匹配[A -z]。"Z"在"a"和"Z"之间排序,但不匹配[a- Z]。

Here are the [A-Z] results:

以下是[A-Z]的结果:

>findstr /nrc:"^[A-Z]" sortedChars.txt
151:A 065
153:â 131
154:ä 132
155:à 133
156:å 134
157:Ä 142
158:Å 143
159:á 160
160:ª 166
161:æ 145
162:Æ 146
163:B 066
164:b 098
165:C 067
166:c 099
167:Ç 128
168:ç 135
169:D 068
170:d 100
171:E 069
172:e 101
173:é 130
174:ê 136
175:ë 137
176:è 138
177:É 144
178:F 070
179:f 102
180:ƒ 159
181:G 071
182:g 103
183:H 072
184:h 104
185:I 073
186:i 105
187:ï 139
188:î 140
189:ì 141
190:í 161
191:J 074
192:j 106
193:K 075
194:k 107
195:L 076
196:l 108
197:M 077
198:m 109
199:N 078
200:n 110
201:ñ 164
202:Ñ 165
203:ⁿ 252
204:O 079
205:o 111
206:ô 147
207:ö 148
208:ò 149
209:Ö 153
210:ó 162
211:º 167
212:P 080
213:p 112
214:Q 081
215:q 113
216:R 082
217:r 114
218:S 083
219:s 115
220:ß 225
221:T 084
222:t 116
223:U 085
224:u 117
225:û 150
226:ù 151
227:ú 163
228:ü 129
229:Ü 154
230:V 086
231:v 118
232:W 087
233:w 119
234:X 088
235:x 120
236:Y 089
237:y 121
238:ÿ 152
239:Z 090
240:z 122

And the [a-z] results

和[a - z]的结果

>findstr /nrc:"^[a-z]" sortedChars.txt
151:A 065
152:a 097
153:â 131
154:ä 132
155:à 133
156:å 134
157:Ä 142
158:Å 143
159:á 160
160:ª 166
161:æ 145
162:Æ 146
163:B 066
164:b 098
165:C 067
166:c 099
167:Ç 128
168:ç 135
169:D 068
170:d 100
171:E 069
172:e 101
173:é 130
174:ê 136
175:ë 137
176:è 138
177:É 144
178:F 070
179:f 102
180:ƒ 159
181:G 071
182:g 103
183:H 072
184:h 104
185:I 073
186:i 105
187:ï 139
188:î 140
189:ì 141
190:í 161
191:J 074
192:j 106
193:K 075
194:k 107
195:L 076
196:l 108
197:M 077
198:m 109
199:N 078
200:n 110
201:ñ 164
202:Ñ 165
203:ⁿ 252
204:O 079
205:o 111
206:ô 147
207:ö 148
208:ò 149
209:Ö 153
210:ó 162
211:º 167
212:P 080
213:p 112
214:Q 081
215:q 113
216:R 082
217:r 114
218:S 083
219:s 115
220:ß 225
221:T 084
222:t 116
223:U 085
224:u 117
225:û 150
226:ù 151
227:ú 163
228:ü 129
229:Ü 154
230:V 086
231:v 118
232:W 087
233:w 119
234:X 088
235:x 120
236:Y 089
237:y 121
238:ÿ 152
240:z 122

Sort sorts upper case before lower case. (EDIT - I just read the help for SORT and learned that it does not differentiate between upper and lower case. The fact that my SORT output consistently put upper before lower is probably a result of the order of the input.) But regex apparently sorts lower case before upper case. All of the following ranges fail to match any characters.

在较低的情况下,对上面的情况进行排序。(编辑-我只是阅读了帮助排序,并了解到它没有区分大小写。事实上,我的排序输出总是在较低的位置上,这可能是输入顺序的结果。但是regex显然会在大写字母前对小写进行排序。下面的所有范围都不能匹配任何字符。

>findstr /nrc:"^[A-a]" sortedChars.txt

>findstr /nrc:"^[B-b]" sortedChars.txt

>findstr /nrc:"^[C-c]" sortedChars.txt

>findstr /nrc:"^[D-d]" sortedChars.txt

Reversing the order finds the characters.

颠倒顺序查找字符。

>findstr /nrc:"^[a-A]" sortedChars.txt
151:A 065
152:a 097

>findstr /nrc:"^[b-B]" sortedChars.txt
163:B 066
164:b 098

>findstr /nrc:"^[c-C]" sortedChars.txt
165:C 067
166:c 099

>findstr /nrc:"^[d-D]" sortedChars.txt
169:D 068
170:d 100

There are additional characters that regex sorts differently than SORT, but I haven't got a precise list.

有一些额外的字符,regex排序不同于排序,但我没有得到一个精确的列表。

#2


3  

So if you want

所以如果你想

  • only numbers : FindStr /R "^[0123-9]*$"

    只有数字:中/ R " ^[0123 - 9]* $”

  • octal : FindStr /R "^[0123-7]*$"

    八进制:中/ R " ^[0123 - 7]* $”

  • hexadécimal : FindStr /R "^[0123-9aAb-Cd-EfF]*$"

    十六进制:FindStr /R“[0123-9aAb-Cd-EfF]*$”

  • alpha with no accent : FindStr /R "^[aAb-Cd-EfFg-Ij-NoOp-St-Uv-YzZ]*$"

    α没有口音:中/ R " ^[aAb-Cd-EfFg-Ij-NoOp-St-Uv-YzZ]* $”

  • alphanumeric : FindStr /R "^[0123-9aAb-Cd-EfFg-Ij-NoOp-St-Uv-YzZ]*$"

    字母数字:中/ R " ^[0123 - 9 - - cd - effg ij艺术展-等待-圣- uv - yzz]* $”

#3


2  

This appears to be caused by the use of ranges within regular expression searches.

这似乎是由于在正则表达式搜索中使用范围而引起的。

It doesn't occur for the first character in the range. It doesn't occur at all for non-ranges.

它不会出现在第一个字符的范围内。它不会在非范围内发生。

> echo a | findstr /r "[A-C]"
> echo b | findstr /r "[A-C]"
    b
> echo c | findstr /r "[A-C]"
    c
> echo d | findstr /r "[A-C]"
> echo b | findstr /r "[B-C]"
> echo c | findstr /r "[B-C]"
    c

> echo a | findstr /r "[ABC]"
> echo b | findstr /r "[ABC]"
> echo c | findstr /r "[ABC]"
> echo d | findstr /r "[ABC]"
> echo b | findstr /r "[BC]"
> echo c | findstr /r "[BC]"

> echo A | findstr /r "[A-C]"
    A
> echo B | findstr /r "[A-C]"
    B
> echo C | findstr /r "[A-C]"
    C
> echo D | findstr /r "[A-C]"

According to the SS64 CMD FINDSTR page (which, in a stunning display of circularity, references this question), the range [A-Z]:

根据SS64 CMD FINDSTR页面(在一个令人震惊的循环显示中,引用这个问题),范围[a - z]:

... includes the complete English alphabet, both upper and lower case (except for "a"), as well as non-English alpha characters with diacriticals.

…包括完整的英文字母,大写和小写(除了“a”),以及非英语字母的字母。

To get around the problem in my environment, I simply used specific regular expressions (such as [ABCD] rather than [A-D]). A more sensible approach for those that are allowed would be to download CygWin or GnuWin32 and use grep from one of those packages.

为了解决环境中的问题,我只是使用了特定的正则表达式(例如[ABCD],而不是[A-D])。更明智的方法是下载CygWin或GnuWin32,并从其中一个包中使用grep。

#4


-1  

Everyone above is wrong. The alpha chars order is the follwoing: aAbBcCdDeE..zZ so echo a | findstr /r "[A-Z]" returns nothing, since a is outside of that range.

上面都是错误的。阿尔法·查尔斯的命令如下:aAbBcCdDeE..因为a在这个范围之外,所以echo一个| findstr /r“[a - z]”什么都不返回。

echo abc|findstr /r "[A-Z][A-Z][A-Z]" also returns nothing, since first range group matches b, second one matches c and the third one matches nothing and thus the whole regex pattern finds nothing.

echo abc|findstr /r [A-Z][A-Z][A-Z] [A-Z][A-Z][A-Z] [A-Z][A-Z][A-Z] [A-Z][A-Z][A-Z] [A-Z][A-Z][A-Z] [A-Z][A-Z][A-Z]" [A-Z]" [A-Z]" [A-Z]" [a

If you like to match any character of latin alphabet - use [a-Z].

如果你喜欢匹配任何拉丁字母的字符-使用[a-Z]。

#1


14  

I believe this is mostly a horrible design flaw.

我认为这主要是一个可怕的设计缺陷。

We all expect the ranges to collate based on the ASCII code value. But they don't - instead the ranges are based on a collation sequence that nearly matches the default sequence used by SORT. EDIT -The exact collation sequence used by FINDSTR is now available at https://*.com/a/20159191/1012053 under the section titled Regex character class ranges [x-y].

我们都希望基于ASCII码值的范围进行排序。但它们没有——相反,这些范围是基于排序序列,几乎与排序所使用的默认序列相匹配。编辑—FINDSTR所使用的精确排序序列现在可以在https://*.com/a/20159191/1012053中使用,它的标题是Regex字符类范围[x-y]。

I prepared a text file containing one line for each extended ASCII character from 1 - 255, excluding 10 (LF), 13 (CR), and 26 (EOF on Windows). On each line I have the character, followed by a space, followed by the decimal code for the character. I then ran the file through SORT and captured the output in a sortedChars.txt file.

我编写了一个文本文件,其中包含了从1 - 255,不包括10 (LF), 13 (CR),和26 (EOF在Windows上)的每个扩展ASCII字符的一行。在每一行上,我都有字符,然后是空格,然后是字符的十进制代码。然后,我通过排序运行该文件,并在一个sortedChars中捕获输出。txt文件。

I now can easily test any regex range against this sorted file and demonstrate how the range is determined by a collation sequence that is nearly the same as SORT.

现在,我可以轻松地对这个已排序的文件进行任何regex范围的测试,并演示如何使用几乎与排序相同的排序序列来确定范围。

>findstr /nrc:"^[0-9]" sortedChars.txt
137:0 048
138:½ 171
139:¼ 172
140:1 049
141:2 050
142:² 253
143:3 051
144:4 052
145:5 053
146:6 054
147:7 055
148:8 056
149:9 057

The results are not quite what we expected in that chars 171, 172 and 253 are thrown in the mix. But the results make perfect sense. The line number prefix corresponds to the SORT collation sequence, and you can see that the range exactly matches according to the SORT sequence.

结果并不是我们所期望的,在这张图表中,有171、172和253。但结果是完全合理的。行号前缀对应排序排序序列,您可以看到按排序顺序匹配的范围。

Here is another range test that exactly follows the SORT sequence:

下面是另一种范围测试,它完全遵循排序顺序:

>findstr /nrc:"^[!-=]" sortedChars.txt
34:! 033
35:" 034
36:# 035
37:$ 036
38:% 037
39:& 038
40:( 040
41:) 041
42:* 042
43:, 044
44:. 046
45:/ 047
46:: 058
47:; 059
48:? 063
49:@ 064
50:[ 091
51:\ 092
52:] 093
53:^ 094
54:_ 095
55:` 096
56:{ 123
57:| 124
58:} 125
59:~ 126
60:¡ 173
61:¿ 168
62:¢ 155
63:£ 156
64:¥ 157
65:₧ 158
66:+ 043
67:∙ 249
68:< 060
69:= 061

There is one small anomaly with alpha characters. Character "a" sorts between "A" and "Z" yet it does not match [A-Z]. "z" sorts after "Z", yet it matches [A-Z]. There is a corresponding problem with [a-z]. "A" sorts before "a", yet it matches [a-z]. "Z" sorts between "a" and "z", yet it does not match [a-z].

有一个小的异常与字母的字符。“a”和“Z”之间的“a”类型,但并不匹配。“z”排序后“z”,但它匹配[A-Z]。[a-z]有一个相应的问题。“A”在“A”之前排序,但它匹配[A -z]。"Z"在"a"和"Z"之间排序,但不匹配[a- Z]。

Here are the [A-Z] results:

以下是[A-Z]的结果:

>findstr /nrc:"^[A-Z]" sortedChars.txt
151:A 065
153:â 131
154:ä 132
155:à 133
156:å 134
157:Ä 142
158:Å 143
159:á 160
160:ª 166
161:æ 145
162:Æ 146
163:B 066
164:b 098
165:C 067
166:c 099
167:Ç 128
168:ç 135
169:D 068
170:d 100
171:E 069
172:e 101
173:é 130
174:ê 136
175:ë 137
176:è 138
177:É 144
178:F 070
179:f 102
180:ƒ 159
181:G 071
182:g 103
183:H 072
184:h 104
185:I 073
186:i 105
187:ï 139
188:î 140
189:ì 141
190:í 161
191:J 074
192:j 106
193:K 075
194:k 107
195:L 076
196:l 108
197:M 077
198:m 109
199:N 078
200:n 110
201:ñ 164
202:Ñ 165
203:ⁿ 252
204:O 079
205:o 111
206:ô 147
207:ö 148
208:ò 149
209:Ö 153
210:ó 162
211:º 167
212:P 080
213:p 112
214:Q 081
215:q 113
216:R 082
217:r 114
218:S 083
219:s 115
220:ß 225
221:T 084
222:t 116
223:U 085
224:u 117
225:û 150
226:ù 151
227:ú 163
228:ü 129
229:Ü 154
230:V 086
231:v 118
232:W 087
233:w 119
234:X 088
235:x 120
236:Y 089
237:y 121
238:ÿ 152
239:Z 090
240:z 122

And the [a-z] results

和[a - z]的结果

>findstr /nrc:"^[a-z]" sortedChars.txt
151:A 065
152:a 097
153:â 131
154:ä 132
155:à 133
156:å 134
157:Ä 142
158:Å 143
159:á 160
160:ª 166
161:æ 145
162:Æ 146
163:B 066
164:b 098
165:C 067
166:c 099
167:Ç 128
168:ç 135
169:D 068
170:d 100
171:E 069
172:e 101
173:é 130
174:ê 136
175:ë 137
176:è 138
177:É 144
178:F 070
179:f 102
180:ƒ 159
181:G 071
182:g 103
183:H 072
184:h 104
185:I 073
186:i 105
187:ï 139
188:î 140
189:ì 141
190:í 161
191:J 074
192:j 106
193:K 075
194:k 107
195:L 076
196:l 108
197:M 077
198:m 109
199:N 078
200:n 110
201:ñ 164
202:Ñ 165
203:ⁿ 252
204:O 079
205:o 111
206:ô 147
207:ö 148
208:ò 149
209:Ö 153
210:ó 162
211:º 167
212:P 080
213:p 112
214:Q 081
215:q 113
216:R 082
217:r 114
218:S 083
219:s 115
220:ß 225
221:T 084
222:t 116
223:U 085
224:u 117
225:û 150
226:ù 151
227:ú 163
228:ü 129
229:Ü 154
230:V 086
231:v 118
232:W 087
233:w 119
234:X 088
235:x 120
236:Y 089
237:y 121
238:ÿ 152
240:z 122

Sort sorts upper case before lower case. (EDIT - I just read the help for SORT and learned that it does not differentiate between upper and lower case. The fact that my SORT output consistently put upper before lower is probably a result of the order of the input.) But regex apparently sorts lower case before upper case. All of the following ranges fail to match any characters.

在较低的情况下,对上面的情况进行排序。(编辑-我只是阅读了帮助排序,并了解到它没有区分大小写。事实上,我的排序输出总是在较低的位置上,这可能是输入顺序的结果。但是regex显然会在大写字母前对小写进行排序。下面的所有范围都不能匹配任何字符。

>findstr /nrc:"^[A-a]" sortedChars.txt

>findstr /nrc:"^[B-b]" sortedChars.txt

>findstr /nrc:"^[C-c]" sortedChars.txt

>findstr /nrc:"^[D-d]" sortedChars.txt

Reversing the order finds the characters.

颠倒顺序查找字符。

>findstr /nrc:"^[a-A]" sortedChars.txt
151:A 065
152:a 097

>findstr /nrc:"^[b-B]" sortedChars.txt
163:B 066
164:b 098

>findstr /nrc:"^[c-C]" sortedChars.txt
165:C 067
166:c 099

>findstr /nrc:"^[d-D]" sortedChars.txt
169:D 068
170:d 100

There are additional characters that regex sorts differently than SORT, but I haven't got a precise list.

有一些额外的字符,regex排序不同于排序,但我没有得到一个精确的列表。

#2


3  

So if you want

所以如果你想

  • only numbers : FindStr /R "^[0123-9]*$"

    只有数字:中/ R " ^[0123 - 9]* $”

  • octal : FindStr /R "^[0123-7]*$"

    八进制:中/ R " ^[0123 - 7]* $”

  • hexadécimal : FindStr /R "^[0123-9aAb-Cd-EfF]*$"

    十六进制:FindStr /R“[0123-9aAb-Cd-EfF]*$”

  • alpha with no accent : FindStr /R "^[aAb-Cd-EfFg-Ij-NoOp-St-Uv-YzZ]*$"

    α没有口音:中/ R " ^[aAb-Cd-EfFg-Ij-NoOp-St-Uv-YzZ]* $”

  • alphanumeric : FindStr /R "^[0123-9aAb-Cd-EfFg-Ij-NoOp-St-Uv-YzZ]*$"

    字母数字:中/ R " ^[0123 - 9 - - cd - effg ij艺术展-等待-圣- uv - yzz]* $”

#3


2  

This appears to be caused by the use of ranges within regular expression searches.

这似乎是由于在正则表达式搜索中使用范围而引起的。

It doesn't occur for the first character in the range. It doesn't occur at all for non-ranges.

它不会出现在第一个字符的范围内。它不会在非范围内发生。

> echo a | findstr /r "[A-C]"
> echo b | findstr /r "[A-C]"
    b
> echo c | findstr /r "[A-C]"
    c
> echo d | findstr /r "[A-C]"
> echo b | findstr /r "[B-C]"
> echo c | findstr /r "[B-C]"
    c

> echo a | findstr /r "[ABC]"
> echo b | findstr /r "[ABC]"
> echo c | findstr /r "[ABC]"
> echo d | findstr /r "[ABC]"
> echo b | findstr /r "[BC]"
> echo c | findstr /r "[BC]"

> echo A | findstr /r "[A-C]"
    A
> echo B | findstr /r "[A-C]"
    B
> echo C | findstr /r "[A-C]"
    C
> echo D | findstr /r "[A-C]"

According to the SS64 CMD FINDSTR page (which, in a stunning display of circularity, references this question), the range [A-Z]:

根据SS64 CMD FINDSTR页面(在一个令人震惊的循环显示中,引用这个问题),范围[a - z]:

... includes the complete English alphabet, both upper and lower case (except for "a"), as well as non-English alpha characters with diacriticals.

…包括完整的英文字母,大写和小写(除了“a”),以及非英语字母的字母。

To get around the problem in my environment, I simply used specific regular expressions (such as [ABCD] rather than [A-D]). A more sensible approach for those that are allowed would be to download CygWin or GnuWin32 and use grep from one of those packages.

为了解决环境中的问题,我只是使用了特定的正则表达式(例如[ABCD],而不是[A-D])。更明智的方法是下载CygWin或GnuWin32,并从其中一个包中使用grep。

#4


-1  

Everyone above is wrong. The alpha chars order is the follwoing: aAbBcCdDeE..zZ so echo a | findstr /r "[A-Z]" returns nothing, since a is outside of that range.

上面都是错误的。阿尔法·查尔斯的命令如下:aAbBcCdDeE..因为a在这个范围之外,所以echo一个| findstr /r“[a - z]”什么都不返回。

echo abc|findstr /r "[A-Z][A-Z][A-Z]" also returns nothing, since first range group matches b, second one matches c and the third one matches nothing and thus the whole regex pattern finds nothing.

echo abc|findstr /r [A-Z][A-Z][A-Z] [A-Z][A-Z][A-Z] [A-Z][A-Z][A-Z] [A-Z][A-Z][A-Z] [A-Z][A-Z][A-Z] [A-Z][A-Z][A-Z]" [A-Z]" [A-Z]" [A-Z]" [a

If you like to match any character of latin alphabet - use [a-Z].

如果你喜欢匹配任何拉丁字母的字符-使用[a-Z]。