Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to get the words after matching string [duplicate]

Below is the content:

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 

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.

How can I do this?

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

like image 914
Chamara Keragala Avatar asked Oct 05 '13 02:10

Chamara Keragala


People also ask

What regex syntax is used for matching any number of repetitions?

A repeat is an expression that is repeated an arbitrary number of times. An expression followed by '*' can be repeated any number of times, including zero. An expression followed by '+' can be repeated any number of times, but at least once.

What does \b do in regular expression?

Simply put: \b allows you to perform a “whole words only” search using a regular expression in the form of \bword\b. A “word character” is a character that can be used to form words. All characters that are not “word characters” are “non-word characters”.


1 Answers

But I need the match result to be ... not in a match group...

For what you are trying to do, this should work. \K resets the starting point of the match.

\bObject Name:\s+\K\S+ 

You can do the same for getting your Security ID matches.

\bSecurity ID:\s+\K\S+ 
like image 126
hwnd Avatar answered Nov 11 '22 04:11

hwnd