正则表达式获得匹配字符串后的单词 [英] Regex to get the words after matching string

查看:541
本文介绍了正则表达式获得匹配字符串后的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是内容:

Subject:
    Security ID:        S-1-5-21-3368353891-1012177287-890106238-22451
    Account Name:       ChamaraKer
    Account Domain:     JIC
    Logon ID:       0x1fffb

Object:
    Object Server:  Security
    Object Type:    File
    Object Name:    D:\ApacheTomcat\apache-tomcat-6.0.36\logs\localhost.2013-07-01.log
    Handle ID:  0x11dc

我需要捕获对象名称后面的单词:该行中的单词。哪个是 D:\ApacheTomcat\apache-tomcat-6.0.36\logs\localhost.2013-07-01.log
我希望有人可以帮助我。

I need to capture the words after the Object Name: word in that line. Which is D:\ApacheTomcat\apache-tomcat-6.0.36\logs\localhost.2013-07-01.log. I hope somebody can help me with this.

^。* \bObject Name\b。* $ matches - 对象名称

^.*\bObject Name\b.*$ matches - Object Name

推荐答案

以下内容适用于您:

[\n\r].*Object Name:\s*([^\n\r]*)

工作示例

您所需的比赛将在捕获组1中。

Your desired match will be in capture group 1.

[\n\r][ \t]*Object Name:[ \t]*([^\n\r]*)

将是类似的,但不允许使用诸如blah Object Name:blah之类的东西,并且还要确保如果在对象名称之后没有实际内容,则不捕获下一行:

Would be similar but not allow for things such as " blah Object Name: blah" and also make sure that not to capture the next line if there is no actual content after "Object Name:"

这篇关于正则表达式获得匹配字符串后的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆