在Linux上的C中使用正则表达式 [英] using regular expressions in C on linux
本文介绍了在Linux上的C中使用正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
团队,
您能告诉我这种特殊模式的含义吗?
我只是一个初学者,在一个网站中发现了这个例子
通过regex.h提供reg表达的示例
Hi Team,
Can you please tell what is the meaning of this particular pattern.
I am just being a beginner and found this as an example in one of the site
providing example for reg expression through regex.h
char *PatternSearch = "[?&]XYZ=\\([[:alnum:]]*\\)";
如果您可以通过示例解释此模式的目的,请感谢您的答复
问候
Appreciate your response if you could explain what does this pattern look for with an example
Regards,
推荐答案
[?&]
是?
或&
之一XYZ=
就是那个精确的文本(区分大小写)
\\(
是左括号字符(
.\\
被编译器转义,因此它将\(
传递给正则表达式
[:alnum:]
是A-Za-z0-9
的简写(无方括号),扩展为ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
.请注意,[]
是此扩展的一部分.
[[:alnum:]]
搜索[A-Za-z0-9]
[[:alnum:]]*
搜索任意数量的[[:alnum:]]
(请参阅上一个)
\\)
是右括号)
.再次\\
被编译器转义,将\(
作为正则表达式传递给
因此,它正在搜索
[?&]
is one of?
or&
XYZ=
is just that exact text (case sensitive)
\\(
is the opening bracket character(
. The\\
is escaped by the compiler, so it is passing\(
into the regex
[:alnum:]
is shorthand forA-Za-z0-9
(no square brackets) which expands toABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
. Note that the[]
is part of this expansion.
[[:alnum:]]
searches for[A-Za-z0-9]
[[:alnum:]]*
searches for any number of[[:alnum:]]
(see previous)
\\)
is the closing bracket character)
. Again\\
is escaped by the compiler, passing\(
in as the regex
So, it is searching for
?XYZ=(/*any characters in here*/)
或
or
&XYZ=(/*any characters in here*/)
这篇关于在Linux上的C中使用正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文