1

I am trying to write a regular expression to extract multiline line from a file that has system call trace. I try to find a system call trace for the error that happens. It is a debugging project. My goal to extract all line between keywords "Before Error" and "After Error" Here are my tries. https://repl.it/@kaloon/LiquidDimgrayParser

May I know what a problem with it?

3
  • 1
    Can you post an example error message? It's hard to write any regex pattern without seeing knowing exactly what the text looks like. Commented Nov 21, 2018 at 20:30
  • the text available on the link at the main post. Just click on the link Commented Nov 21, 2018 at 20:38
  • @kaloon: It is actually preferred here to have searchable code within the question. Commented Nov 21, 2018 at 21:04

1 Answer 1

1

Something like the following should work for you:

import re
pattern = re.compile(".*Before Error(.*)After Error.*", re.DOTALL)
pattern.findall(str1)
Sign up to request clarification or add additional context in comments.

5 Comments

I updated it with a working version, tested in your link.
Thanks. It works :) . But What about If I want to just extract the line between them without extract the same the line that has "Before Error " and "After Error"
Using pattern = re.compile(".*Before Error[^\n]*\n(.*)\n.*After Error.*", re.DOTALL) should exclude the lines containing "Before Error" and "After Error".
Hi Tim, I tried the last update. it got an empty result.
I'm not sure - for me, the second pattern returns the following: ['[pid 16701] 16:08:36 getuid() = 10114\n[pid 16701] 16:08:36 getuid() = 10114\n[pid 16701] 16:08:36 ioctl(8, BINDER_WRITE_READ, 0x7fc4f92e88) = 0\n[pid 16701] 16:08:36 ioctl(8, BINDER_WRITE_READ, 0x7fc4f92e88) = 0\n\xe2\x80\xa6[pid 16701] 16:08:36 ioctl(47, ASHMEM_GET_SIZE, 0) = 84\n[pid 16701] 16:08:36 close(47) = 0\n[pid 16701] 16:08:36 getuid() = 10114']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.