[英]I have a comma delimited string and I want to find one particular field in that using Regex in C#
This is my string: 这是我的字符串:
"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"
I want to get the date that is preceding the word "Motot Fuel Dest"
using regex. 我想使用正则表达式获取"Motot Fuel Dest"
一词之前的日期。 How can we get that? 我们怎么能得到呢?
Could use something like this... 可以使用这样的东西...
/(?<=")[^"]+(?=","Motor Fuel Dest)/
Depending on your regex flavor the syntax may be different. 根据您的正则表达式风格,语法可能有所不同。
Edit: .NET version of solution 编辑:.NET版本的解决方案
resultString = Regex.Match(subjectString, "(?<=\")[^\"]+(?=\",\"Motor Fuel Dest)").Value;
It's not something special, just lookbehind/lookahead capture only what you need. 这没什么特别的,只是先行查找/先行捕获仅需要的内容。
This will also work... 这也将起作用...
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);
Then you have the value as a DateTime
in the theValue
field. 然后,在theValue
字段中将值作为DateTime
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.