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]
.
精彩评论