Regex C# searching file for matching pattern starts with and end with -
in c# want search match occurs starting integer in parenthesis followed these characters "pla" parenthesis , "match" (i'll read memory) until next set reached.
thus sample code
(1965 ("pla") ("gen_angle") ("line line angle") ( ("clinesegs" 3565.01 1265.99 "surface") ("clinesegs" 3618.02 1255.00 "surface") ) ((3586.02 1267.20 "surface")) (120.000) (90.000) ) (1966 ("pla") ("gen_angle") ("line line angle") ( ("clinesegs" 3831.98 1255.00 "surface") ("clinesegs" 3882.92 1268.07 "surface") ) ((3863.98 1267.20 "surface")) (120.000) (90.000) )
i want "match" data , grab data based on knowing "1965" id i'm looking for.
(1965 ("pla") ("gen_angle") ("line line angle") ( ("clinesegs" 3565.01 1265.99 "surface") ("clinesegs" 3618.02 1255.00 "surface") ) ((3586.02 1267.20 "surface")) (120.000) (90.000) )
i can find "(1965" with:
(\(1965)
.. or (with (add) in front):
[(](add){1}\r\n\r\n\t\s[(][0-9]{4,}\r\n\r\n\t\s\s(\("){1}[a-za-z]{1,}("\)){1}
.. can't seem these types of regex work must spacing , line breaks
stuck understanding matching of end pla , "detecting" ending )
before next set of data starts (1966 ("pla")
figured use in match detect end of match, not include in findings.
if know it's followed (1966 ("pla")
doesn't occur inside of data, can use like:
(?xs) # ignore spaces, comments , make . match \n \(1965\s+\("pla"\) .*? # ungreedy (?=\(1966\s+\("pla"\)|$) # lookahead not include in match
which can quoted in c# so:
var re = @"(?xs) # ignore spaces, comments , make . match \n \(1965\s+\(""pla""\) .*? # ungreedy (?=\(1966\s+\(""pla""\)|$) # lookahead not include in match ";
Comments
Post a Comment