regex - How to remove strings between two characters using regular expression python -


i trying clean log , want extract general information message. newie python , learn regular expression yesterday , have problems.

my message this:

 report zsim_random_duration_ started  report zsim_system_activity started  report /bdl/task_scheduler started  report zsim_job_create started  report rsbtcrte started  report sapmssy started  report rsrzllg_actual started  report rsrzllg started  report rgwmon_send_nilist started 

i try code:

clean_special2=re.sub(r'^[report] [^1-9] [started]','',text) 

but think code remove rows want keep format report .....started. want remove jobs name in middle.

i expect outcome looks this:

report started 

anyone can me idea? thank much!

try this:

clean_special2=re.sub(r'(?<=^report\b).*(?=\bstarted)',' ',text) 

explanation: (?<=...) positive lookbehind, e.g. string must match content of group, not captured , not replaced. same thing on other side positive look-ahead (?=...). \b word boundary, between these words matched. since trim away whitespace, replacement single whitespace.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -