Products
GG网络技术分享 2025-03-18 16:15 8
I\'m trying to create a regular expression that is to be integrated in monitoring services. They are validated using golang regex.
So I was trying to create a regex that validates java exceptions.
For example I have these exceptions (they are seperate lines)java.lang.NoSuchMethodException: ...java.lang.IllegalAccessException: ...
And I need a regular expressions that accepts exceptions only. Not errors, nor other types.
I\'m able to catch java messages with this regular expression
pattern: \"^java.lang\"
But that also includes all types of errors, which is not intent.
I was trying to make the regex to catch the word \"exception\" at the end, but I\'m not sure how.图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议我正在尝试创建要集成到监视服务中的正则表达式。 他们使用golang正则表达式进行了验证。</ p>
因此,我试图创建一个可验证Java异常的正则表达式。
例如,我有这些异常(它们是单独的行)</ p>
java.lang.NoSuchMethodException:... java.lang.IllegalAccessException:...
</ code> </ pre>
我需要一个 仅接受例外</ strong>的正则表达式。 不是错误,也不是其他类型。</ p>
我能够使用此正则表达式捕获Java消息</ p>
模式:“ ^ java。 lang“ </ code> </ pre>
但这还包括所有类型的错误,这不是故意的。
我正在尝试使正则表达式在“正则表达式”处捕获“ exception”一词。 最后,但是我不确定如何。</ p>
</ div>
网友观点:
You could match any character zero or more times no greedy and then match Exception: .*?Exception:
after ^java\\.lang\\.
.
^java\\.lang\\..*?Exception:
Note to escape the dot to match it literally.
30分钟玩转「正则表达式」
简介
推荐阅读:Jeffrey Friedl 《精通正则表达式(第3版)》,本文是该书的读书笔记
。
定义
正则表达式:regular expression, regex,是用来描述或者匹配一系列符合某个句法规则的字符串的单个字符串。正则表达式这个概念最初是由Unix中的工具软件(例如sed和grep)普及开的。
分类
- BREs, 基本的正则表达式(Basic Regular Expression)
- EREs, 扩展的正则表达式(Extended Regular Expression)
- PREs, Perl 的正则表达式(Perl Regular Expression)
Linux常用文本工具
只有掌握了正则表达式,才能全面地掌握 Linux 下的常用文本工具(例如:grep、egrep、GUN sed、 Awk 等)的用法。
grep, egrep
Demand feedback