我有一个逗号分隔的字符串,我想在c#中使用Regex找到一个特定的字段
本文关键字:字段 一个 Regex 分隔 有一个 字符串 | 更新日期: 2023-09-27 18:17:55
这是我的字符串:
"0949418001","12/12/2011","12/21/2011","0010043309","EFT ","Net 10 Days From Ship Date","","","FOB Origin/Collect","","","0000835369","DUPRE TRANSPORTS INC","DUPR ","0231653047","1/23/2012","Motor Fuel Dest","1049930","8784.00","8796.00","8784.00","UG6 ","N","0.196500","1726.06","25405.51","TAX ","REG","","PASADENA,TX,COP,RFYC (03FV)"," ","0000835369","835369","1726.06","01/23/2012","0.00","23679.45"
我想使用正则表达式获得单词"Motot Fuel Dest"
前面的日期。我们怎么才能得到呢?
可以这样写…
/(?<=")[^"]+(?=","Motor Fuel Dest)/
根据您的正则表达式风格,语法可能会有所不同。
编辑:.NET版本的解决方案
resultString = Regex.Match(subjectString, "(?<='")[^'"]+(?='",'"Motor Fuel Dest)").Value;
这不是什么特别的东西,只是向后看/向前看,只捕捉你需要的
这也可以…
var dateMatch = Regex.Match(myInputString, @"(?<Date>'d{1,2}/'d{1,2}/'d{4})"",Motor'sFuel'sDest");
DateTime theValue = DateTime.Parse(dateMatch.Groups["Date"].Value);
那么在theValue
字段中,您有作为DateTime
的值。