我可以否定POSIX括号表达式吗? [英] Can I do a negation of a POSIX bracket expression?
问题描述
我知道我可以使用POSIX括号表达式[[:space:]]
搜索与空格匹配的内容.我可以使用POSIX括号表达式搜索不匹配空格的内容吗?特别是,它应该匹配的字符包括字母和括号((
).
I know I can search for something matching a space with the POSIX bracket expression [[:space:]]
. Can I do a search for something not matching a space using a POSIX bracket expression? In particular, the characters it should match include letters, and parentheses ((
).
[[:graph:]]
看起来有些模糊:
[[:graph:]]
-非空白字符(不包括空格,控制字符等)
[[:graph:]]
- Non-blank character (excludes spaces, control characters, and similar)
推荐答案
您在这里混淆了两件事:a 括号表达式和POSIX字符类.外部[...]
是括号表达式,可以用紧跟在[
之后的^
取反. POSIX字符类是[:
+ name
+ :]
构造,仅在括号表达式内有效.
You confuse two things here: a bracket expression and a POSIX character class. The outer [...]
is a bracket expression, and it can be negated with a ^
that immediately follows [
. A POSIX character class is a [:
+name
+:]
construct that only works inside bracket expressions.
因此,在您的情况下,[[:space:]]
模式是一个括号表达式,仅包含一个与空白匹配的POSIX字符类:
So, in your case, [[:space:]]
pattern is a bracket expression containing just 1 POSIX character class that matches a whitespace:
-
[
-打开方括号表达式-
[:space:]
-空格的POSIX字符类
[
- opening a bracket expression[:space:]
- a POSIX character class for whitespace
要否定它,只需像通常的NFA中那样添加
^
字符类 :[^[:space:]]
.To negate it, just add the
^
as in usual NFA character classes:[^[:space:]]
.请注意,由于POSIX和常见的NFA regex世界遵循不同的术语,因此我故意区分术语括号表达","POSIX字符类"和字符类".
Note I deliberately differentiate the terms "bracket expression", "POSIX character class" and "character class" since POSIX and common NFA regex worlds adhere to different terminology.
这篇关于我可以否定POSIX括号表达式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-