bash [:space:] 和 [:blank:] 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15767863/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 05:04:26  来源:igfitidea点击:

What's the difference between [:space:] and [:blank:]?

regexbashgrep

提问by Julien Grenier

From the A Brief Introduction to Regular Expressions

正则表达式简介

[:blank:] matches a space or a tab.

[:blank:] 匹配空格或制表符。

[:space:] matches whitespace characters (space and horizontal tab).

[:space:] 匹配空白字符(空格和水平制表符)。

To me both definitions are the same and I was wondering if they are really duplicates?

对我来说,这两个定义是相同的,我想知道它们是否真的重复?

If they are different, what are the differences?

如果它们不同,它们的区别是什么?

回答by Thor

For the GNU tools the following from grep.infoapplies:

对于 GNU 工具,以下内容grep.info适用:

[:blank:]

     Blank characters: space and tab.

[:space:]

     Space characters: in the 'C' locale, this is tab, newline,
     vertical tab, form feed, carriage return, and space.

You can find the section with this command:

您可以使用以下命令找到该部分:

info grep 'Regular Expressions' 'Character Classes and Bracket Expressions'

回答by JaredPar

A better explanation of what they each match is available here

在这里可以更好地解释他们每场比赛的内容

The biggest difference is that [:space:]will also match items like new line characters

最大的区别是[:space:]还会匹配换行符之类的项目

回答by karthi

A space means to pressing a space bar and tab

空格表示按空格键和制表符

A white space means it carries the newline,tab,form feed and carriage return and also space that's all.

空格意味着它带有换行符、制表符、换页符和回车符以及空格。