开发者

help with regular expression to capture everything in a line

开发者 https://www.devze.com 2023-03-08 14:43 出处:网络
I am wondering if there is a specific regular expression I can write to retrieve any information that follows \'Log1:\' at the beginning of the line. This is what I have tried so far:

I am wondering if there is a specific regular expression I can write to retrieve any information that follows 'Log1:' at the beginning of the line. This is what I have tried so far:

^Log1: ([\w|\s]*)$

but this only works if there are words and spaces, I want it to be able to retrieve anything that follows.. except the new line character or characters that are not really used in writing.

开发者_开发知识库

Log1: important stuff here

Log1: it can have (), [ ].

Any help appreciated.


^Log1: (.*)$

The . matches any character.


You could try something like this:

s.split(/^Log1: */)[1]

This will return nil if there is no leading Log1 and the rest of the line, otherwise. If the line has terminating characters you don't want:

s.split(/^Log1: */)[1].chomp


Do you want to read all lines in your log file, or are there some that don't start with Log1:? If the former, I'd just do line[7..-1].

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号