regex: match line and proceeding lines until match but include contents before and after match -


i trying scan log file until match1 shows proceed match lines after match1 until match2 found. but! need match contents before match1 on same line , contents after match2 on same line.

so far using following mutliline flag cannot figure out how gather before , after content on respected lines of matches.

match1(.*)match2

text:

2015-05-05 17:08:25 name: line should not included   2015-05-05 17:08:25 name: match1   2015-05-05 17:08:25 name: contents , stuff   2015-05-05 17:08:25 name: match2 more stuff   2015-05-05 17:08:25 name: line should not included   

i want match:

2015-05-05 17:08:25 name: match1   2015-05-05 17:08:25 name: contents , stuff   2015-05-05 17:08:25 name: match2 more stuff   

note: beginning of each line not numbers , there complete blank lines between intended match.

using multiline option (/m or (?m) in flavors) , not using singleline option (/s or (?s)), can match with

.*match1[\s\s]*?match2.* 

test live on regex101.com.

explanation:

.*        # match number of characters except newlines match1    # match "match1" [\s\s]*?  # match number of characters including newlines, few possible match2    # match "match2" .*        # match rest of characters on line 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -