[英]Regex match doesn't contain full match text
我在使用正則表達式匹配時遇到問題,但不包含匹配內容的全文。 它只包含月份名稱的最后一個字母,以及日期和年份部分。 我認為它將包含完整的月份名稱,以及日期和年份部分,因為這是我的正則表達式包含的內容,但由於某種原因它不包含。
這是我復制我的問題的例子: https : //ideone.com/wJPj1d
using System;
using System.Text;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
string text = "<strong>Date of Hire: </strong>November 2, 2015<br />";
string foundMatch = "No match found";
Regex dateFormat = new Regex("[January|February|March|April|May|June|July|August|September|October|November|December] [0-9]{1,2}, [0-9]{4}");
MatchCollection matches = dateFormat.Matches(text);
if(matches.Count > 0)
{
foundMatch = matches[0].ToString();
}
Console.WriteLine(foundMatch);
}
}
我得到的輸出是: r 2, 2015
我期望它是什么: November 2, 2015
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.