How to input special character in cmd?

后端 未结 2 2114
一向
一向 2020-12-19 08:46

I have written a c program that retrieves arguments from the command line under Windows. One of the arguments is a regular expression. So I need to retrieve special characte

2条回答
  •  甜味超标
    2020-12-19 09:02

    You can put the arguments in quotes:

    myprogram.exe "(this is some text, with special characters.)"
    

    Though I wouldn't assume that parentheses cause problems unless you are using blocks for conditional statements or loops in a batch file. The usual array of characters that are treated specially by the shell and need quoting or escaping are:

    & | > < ^
    

    If you use those in your regular expression, then you need quotes, or escape those characters:

    myprogram "(.*)|[a-f]+"
    myprogram (.*)^|[a-f]+
    

    (^ is the escape character which causes the following character to be not interpreted by the shell but instead used literally)

提交回复
热议问题