如何在cmd中输入特殊字符?

Jic*_*hao 6 shell cmd

我编写了一个ac程序,它从Windows下的命令行中检索参数.其中一个论点是正则表达式.所以我需要检索特殊字符,如"(,."等,但cmd.exe将"("视为一个特殊字符.

我怎么能输入这些特殊字符?

谢谢.

pax*_*blo 9

您通常可以为任何角色添加前缀^以关闭其特殊性质.例如:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Pax>echo No ^<redirection^> here and can also do ^
More? multi-line, ^(parentheses^) and ^^ itself
No <redirection> here and can also do multi-line, (parentheses) and ^ itself

C:\Documents and Settings\Pax>
Run Code Online (Sandbox Code Playgroud)

这是一个插入符号后面跟着一个输入符号do.


Joe*_*oey 8

您可以将参数放在引号中:

myprogram.exe "(this is some text, with special characters.)"
Run Code Online (Sandbox Code Playgroud)

虽然我不会假设括号会导致问题,除非您在批处理文件中使用块作为条件语句或循环.由shell专门处理并需要引用或转义的常用字符数组是:

& | > < ^
Run Code Online (Sandbox Code Playgroud)

如果您在正则表达式中使用它们,那么您需要引号,或者转义这些字符:

myprogram "(.*)|[a-f]+"
myprogram (.*)^|[a-f]+
Run Code Online (Sandbox Code Playgroud)

(^转义字符,它导致后续字符不被shell解释,而是字面上使用)