Changes

Jump to: navigation, search

OPS102 - Regular Expressions

1,014 bytes added, 11:06, 7 December 2023
Using Regular Expressions
* Languages
** Powershell
** Python
** JavaScript
** Perl
** ...and many others!
 
== Windows findstr and Regular Expressions ==
 
The Windows <code>findstr</code> command accepts regular expressions or literal expressions. It will guess what you're using, and may guess incorrectly, so it's best to use the <code>/R</code> and <code>/L</code> optons to directly specify if your search pattern is a regexp or literal.
 
Findstr permits multiple search patterns in a quoted string, separated by a space; this acts like a type of alternation. However, this makes it impossible to use a literal space in a search pattern. If you wish to include a space in your search pattern, prepend <code>/C:</code> to your search string. You can use multiple <code>/C:</code> search strings.
 
For example, <code>FINDSTR /R /C:"red" /C:"blue" INPUTFILE</code> is roughly equivalent to <code>grep -E "red|blue" INPUTFILE</code>
 
Findstr is also limited to (approximately) 127 characters in the regular expression.
 
For information on findstr's regular expression dialect, see <code>help findstr</code>

Navigation menu