Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 使用sed匹配除正斜杠以外的非数字_Regex_Linux_Unix_Sed - Fatal编程技术网

Regex 使用sed匹配除正斜杠以外的非数字

Regex 使用sed匹配除正斜杠以外的非数字,regex,linux,unix,sed,Regex,Linux,Unix,Sed,我知道我可以使用以下方法匹配非数字: sed's/[^0-9]//g' 但如何匹配除正斜杠以外的非数字 先谢谢你 ~Chris也许是这样: sed 's/[^0-9/]|//g' 如何匹配除正斜杠以外的非数字 当我这样重新表述问题时,我发现更容易思考这个问题: 除了数字和前斜杠,我如何匹配所有内容 为此,只需将正斜杠添加到角色类: sed 's/[^0-9/]//g' 这意味着您希望匹配除数字和正斜杠以外的所有内容。效果非常好。谢谢。sed字符类确实不同于其他也使用/作为分隔符的语言[\/]

我知道我可以使用以下方法匹配非数字:

sed's/[^0-9]//g'

但如何匹配除正斜杠以外的非数字

先谢谢你

~Chris

也许是这样:

sed 's/[^0-9/]|//g'
如何匹配除正斜杠以外的非数字

当我这样重新表述问题时,我发现更容易思考这个问题:

除了数字和前斜杠,我如何匹配所有内容

为此,只需将正斜杠添加到角色类:

sed 's/[^0-9/]//g'

这意味着您希望匹配除数字和正斜杠以外的所有内容。

效果非常好。谢谢。
sed
字符类确实不同于其他也使用
/
作为分隔符的语言[\/]将与
/
\
匹配。您的初始答案似乎正确吗?这一个将匹配正斜杠,不例外。我想你可以查看我对NPE答案的评论<字符类中的代码>/不必在sed中转义。如果您“转义”它,您将最终在character类中添加
\