[.NET]Pass所有字的Regular Expression

Pass所有字的Regular Expression

在網路上有看到 Pass所有字的Regular Expression 為 "[\s\S]*" 。

所以加上測試的範例記錄下來。

static void Main(string[] args)
{
	Console.WriteLine(PassAllChars(@"c:\abc.txt"));
	Console.WriteLine(PassAllChars(@"c:\中文.txt"));
	Console.WriteLine(PassAllChars(@"c:\中文\亂碼客.jpg"));
	Console.WriteLine(PassAllChars(@"c:\中文\亂-碼_客@.jpg"));
}


public static string PassAllChars(string value)
{
	//http://www.codeproject.com/Tips/321828/Checking-for-any-character-using-regular-expressio
	string validationRegex = @"[\s\S]*";
	string result = string.Empty;
	Match match = Regex.Match(value, validationRegex,
		RegexOptions.IgnoreCase);
	if (match.Success)
	{
		result = match.Groups[0].Value;
	}
	return result;
}

image

 

參考資料

Checking for "any character" using regular expressions in multiline text

Hi, 

亂馬客Blog已移到了 「亂馬客​ : Re:從零開始的軟體開發生活

請大家繼續支持 ^_^