首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >/\*\*注释regex: egrep“( text.txt )”(text.txt)

/\*\*注释regex: egrep“( text.txt )”(text.txt)
EN

Unix & Linux用户
提问于 2015-11-06 14:29:31
回答 2查看 470关注 0票数 1

我试图提取开始或结束Java注释的行:

我拥有的是:

“egrep "(/**而论)”text.txt“

我注意到,这适用于所有行(如/*注释*/),但只包含/*、/**、**/或*/ /的行除外,并且在此之前或之后不包含任何内容。

为什么会这样呢?

EN

回答 2

Unix & Linux用户

发布于 2015-11-06 14:33:19

您的模式egrep "(/** | /* | */ | **/)" text.txt包含显式空格;尝试不使用它们:egrep "(/**|/*|*/|**/)" text.txt

票数 1
EN

Unix & Linux用户

发布于 2015-11-06 14:41:26

您在模式中包含空格,并且忘记了以//开头的注释行。

通过以下方式:

代码语言:javascript
复制
egrep "(/\*\*|/\*|\*/|\*\*/|//)" text.txt

我看到所有开始或结束注释的行,包括只包含标记的行。例如..。

text.txt:

代码语言:javascript
复制
this should not be there
// this should be there
/* and this too */
/** even this
should be there too **/
/* or
that
also */
not this
/*
*/
/**
**/

输出:

代码语言:javascript
复制
// this should be there
/* and this too */
/** even this
should be there too **/
/* or
also */
/*
*/
/**
**/
票数 0
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/241255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档