简体   繁体   English

正则表达式匹配字符串中的两个单词

[英]Regex to match two words in a string

I have a string 我有一个弦

"13572_BranchInformationReport_2012-06-28.zip","13572_BranchInformationReport_2012-06-28.zip",0,"184296"," Jun 28 1:30","/icons/default.gif" “ 13572_BranchInformationReport_2012-06-28.zip”,“ 13572_BranchInformationReport_2012-06-28.zip”,0,“ 184296”,“ Jun 28 1:30”,“ / icons / default.gif”

What could be the Regex If i want to extract Jun 28 from this string using c#. 如果我想使用c#从此字符串中提取Jun 28 ,则可能是正则表达式。

This seems to be a CSV record. 这似乎是CSV记录。 If so I suggest to use standard string.Split() function to extract the single components and extract the date by trimming the token containing the date, regex should be used if there is no simpler way to achieve what you need. 如果是这样,我建议使用标准的string.Split()函数提取单个组件并通过修剪包含日期的标记来提取日期,如果没有更简单的方法来实现所需的功能,则应使用regex。

如果您知道月份名称缩写的格式,则可以使用以下格式:

@"((Jan|Feb|Mar|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s[0-9]+)(?<!\\s)"

Assuming that the structure of the string is always the same: 假设字符串的结构始终相同:

@".*\"".\"".*\"".\""([\w]+ [\w]+) .*\"".\"".*"

and then us the 然后我们

match.Groups[1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM