jdskty
jdskty

Reputation: 91

Regex must match two conditions

I've been trying to match lines on two requirements but can't seem to combine the two to get matches.

I have to have S OZN and then do a search for CME 2 # 1 # 1. I tried using S OZN (CME 2 \d+ 1 \d+ 1) where # is a number typically with 7 numbers but no matches.

Some sample data. I've highlighted my match positions in bold. These aren't the entire lines. The lines are from a log4net file. I've shaved off the timestamps to fit this page.

S OZN T$ 116700 T$ 123600 12/27/2013 1449025 3559247 0.015625 CME 2 3451471 1 3451026 1

S OZB U3 116702 U3 123602 12/27/2013 1449012 3532393 0.015625 CME 2 3451048 1 3451491 -1

S OZN T$ 116700 T$ 123600 12/27/2013 1449025 3578191 0.015625 CME 2 3538674 1 3538771 1

S OZN T$ 116700 T$ 123600 12/27/2013 1449025 3612539 0.015625 CME 2 3451476 1 3451036 1

S OZN T$ 116700 T$ 123600 12/27/2013 1449025 3559770 0.015625 CME 2 3451193 1 3451519 -2

Upvotes: 0

Views: 553

Answers (2)

alpha bravo
alpha bravo

Reputation: 7948

based on your trial this pattern should solve it S OZN.*?(CME 2 \d+ 1 \d+ 1)

Upvotes: 0

Phil Perry
Phil Perry

Reputation: 2130

You've got a bunch of text between S OZN and CME which you need to skip over. Are you interested in grabbing the two numbers?

S OZN(.*?)CME\s2\s(\d+)\s1\s(\d+)

might do the job (I haven't checked it... (.*?) is supposed to be a "non-greedy" match of anything but not CME). If it doesn't work, and there is a fixed length of text to skip over, try

S OZN(.{57})CME\s2\s(\d+)\s1\s(\d+)

if I counted the length correctly. $2 and $3 should be the values you're going after.

Upvotes: 1

Related Questions