How can i get a range of 3 to 5 lowercase letters using findstr with regular expressions.
For example:
abc
defg
aqwer
Any of the above should match. SO far the only way i know to do it is like this:
findstr /rc:"[a-z][a-z][a-z][a-z][a-z]" .\*
findstr /rc:"[a-z][a-z][a-z][a-z]" .\*
findstr /rc:"[a-z][a-z][a-z]" .\*
is there a way to do it in one command?
findstr in dos - regular expressions
Moderator: DosItHelp
Re: findstr in dos - regular expressions
This is one way, but there is a bug with multiple strings and and the /i switch should be used too.
findstr /r /c:"[a-z][a-z][a-z][a-z][a-z]" /c:"[a-z][a-z][a-z][a-z]" /c:"[a-z][a-z][a-z]" .\*
A problem with your implementation is that this will match any number of lowercase letter strings over 2 characters
findstr /r /c:"[a-z][a-z][a-z]" .\*
You need to limit the regexp by the characteristics of the input text.
Reply with a sample of the text and what you want, if you would like some ideas.
findstr /r /c:"[a-z][a-z][a-z][a-z][a-z]" /c:"[a-z][a-z][a-z][a-z]" /c:"[a-z][a-z][a-z]" .\*
A problem with your implementation is that this will match any number of lowercase letter strings over 2 characters
findstr /r /c:"[a-z][a-z][a-z]" .\*
You need to limit the regexp by the characteristics of the input text.
Reply with a sample of the text and what you want, if you would like some ideas.
Re: findstr in dos - regular expressions
Sorry, there is not a good solution.
FINDSTR has very primitive (lousy) regex support.
What you posted does not even work because FINDSTR has a screwy implementation of regex ranges: [a-z] doesn't only match lower case letters - it also matches A-Y, as well as some non-English characters.
The only way to match lower case English characters with FINDSTR is to use [abcdefghijklmnopqrstuvwxyz].
The only repeat specification that FINDSTR supports is *, which matches zero or more times.
The maximum regex search string length on Vista and beyond is 254 characters. The best you can do on modern platforms is this god-awful search (note the use of line continuation):
On XP, the maximum regex search string length is only 127 characters. So it is absolutely impossible to use FINDSTR to match 3-5 lower case letters on XP
For a complete description of the crappy FINDSTR range implementation - see Why does findstr not handle case properly (in some circumstances)?
For an exhaustive listing of FINDSTR quirks, see What are the undocumented features and limitations of the Windows FINDSTR command?
--------------
Dave Benham


What you posted does not even work because FINDSTR has a screwy implementation of regex ranges: [a-z] doesn't only match lower case letters - it also matches A-Y, as well as some non-English characters.
The only way to match lower case English characters with FINDSTR is to use [abcdefghijklmnopqrstuvwxyz].
The only repeat specification that FINDSTR supports is *, which matches zero or more times.
The maximum regex search string length on Vista and beyond is 254 characters. The best you can do on modern platforms is this god-awful search (note the use of line continuation):
Code: Select all
findstr /r /c:"[abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz]" ^
/c:"[abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz]" ^
/c:"[abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz]"
On XP, the maximum regex search string length is only 127 characters. So it is absolutely impossible to use FINDSTR to match 3-5 lower case letters on XP

For a complete description of the crappy FINDSTR range implementation - see Why does findstr not handle case properly (in some circumstances)?
For an exhaustive listing of FINDSTR quirks, see What are the undocumented features and limitations of the Windows FINDSTR command?
--------------
The bug is restricted to multiple string literal searches. The /I switch is not needed when using multiple regex searches.foxidrive wrote:but there is a bug with multiple strings and and the /i switch should be used too.
Dave Benham
Re: findstr in dos - regular expressions
dbenham wrote:The maximum regex search string length on Vista and beyond is 254 characters. The best you can do on modern platforms is this god-awful search (note the use of line continuation):Code: Select all
findstr /r /c:"[abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz]" ^
/c:"[abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz]" ^
/c:"[abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz]"
On XP, the maximum regex search string length is only 127 characters. So it is absolutely impossible to use FINDSTR to match 3-5 lower case letters on XP![]()
But this will match any matching string for 3 or more characters. Still not what the OP wants.
findstr /r /c:"[abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz][abcdefghijklmnopqrstuvwxyz]" e.txt
The bug is restricted to multiple string literal searches. The /I switch is not needed when using multiple regex searches.
Thanks.
Re: findstr in dos - regular expressions
foxidrive wrote:But this will match any matching string for 3 or more characters. Still not what the OP wants.
It will match any line that contains 3 to 5 consecutive lower case letters anywhere within the string, which is what I thought the OP asked for. But now that you question it, I realize it is a silly requirement. Simply asking for a line that contains 3 consecutive lower case letters would give the same result.
But put add some additional terms to the beginning and end of the search strings, and then it becomes useful (ignoring the fact that the syntax is totally impractical).
If the intent is to match lines that consist solely of 3-5 lower case letters, then simply add the /X option.
Dave Benham
Last edited by dbenham on 19 Apr 2013 14:22, edited 1 time in total.
-
- Posts: 2
- Joined: 18 Apr 2013 20:40
Re: findstr in dos - regular expressions
I found the way!!!!
findstr /s /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]\> " .\*
findstr /s /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]\> " .\*
Re: findstr in dos - regular expressions
No, that will also match upper case letters A through Y. Did you even read my posts
FINDSTR is not a good option for your stated requirements.
You should download and use a version of grep for Windows. The gnu Win32 project has a good free version of grep for Windows: http://gnuwin32.sourceforge.net/packages/grep.htm
Dave Benham


FINDSTR is not a good option for your stated requirements.
You should download and use a version of grep for Windows. The gnu Win32 project has a good free version of grep for Windows: http://gnuwin32.sourceforge.net/packages/grep.htm
Dave Benham