Solved search a regex using dos

August 16, 2011 at 06:45:26
Specs: Windows XP
Hi All,

I understand that findstr /s "href" *.* will find all the strings with 'href' in the current directory and subsirectory in DOS. I would like to search for ip addresses instead of simple strings.I referred http://regexlib.com/Search.aspx?k=i... to get the reg exp expression. However Can anyone tell me how to search for this regexpression in dos. I tried with no luck the below

findstr /r "/^(?:(?:1\d?\d|[1-9]?\d|2[0-4]\d|25[0-5])\.){3}(?:1\d?\d|[1-9]?\d|2[0-4]\d|25[0-5])$/" *.*


See More: search a regex using dos

Report •

#1
August 16, 2011 at 07:52:21
✔ Best Answer
I'm afraid that the regular expressions accepted by the findstr command are rather limited, so I don't think there is an easy answer to this. The only way that I could think to do it would be with a serites of findstr, each looking for a particular subset of ip addresses.

For example, you would start with one that looked for single digits in each position; then one with single digits in the first three positions, and a double digit string in the last position; then single digits in the first three positions and a triple digit in the last position.

The last case starts to get difficult. If the first of the three digits is "1" then the next two can be anything. If it's "2" then the second digit has to be less than "6"; and if it's "5" then the third digit has to be less than "6".

Continuing in this manner through all possibilities you would build up a rather long list of findstr expressions. You would apply each in turn.

TBH, I don't think it's worth the trouble!

If you really want to do this, install Perl on your computer, and use that rather than findstr to do the matching. The original expression that you gave should work in Perl.


Report •
Related Solutions


Ask Question