Python newbie here.
I have a program named zeroOrMore.py
It reads a regular expression (regex) from stdin.
I invoke the program like this:
python zeroOrMode.py (ab)*(p|q)+
That results in this error message:
'q)+' is not recognized as an internal or external command, operable program or batch file.
I discovered that if I enclose the regex in double quotes:
python zeroOrMode.py "(ab)*(p|q)+"
then there is no error.
Is there a way to accomplish this without wrapping the regex in double quotes? Here's how my program inputs the regex:
regex = sys.argv[1]
This isn't Python; it's CMD. The regex you're giving to Python is being interpreted by the command prompt first. The pipe (
|
) is the batch command for piping input to the following program. Basically, CMD is reading the command line like so:It's trying to take the result of running
zeroOrMode.py
(I think you meant more?) with(ab)*(p
and piping the output to the (nonexistent) programq)+
.There isn't really much of a solution to this, unfortunately. You could always escape the pipe like so:
The caret (
^
) will cause any special meanings the next character has to be ignored.