我想在字符串中找到特定的子字符串模式。在某种程度上我可以得到但不完全是我想要提取的内容。
我正在开发一个控制台应用程序。下面我提到了代码
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string item = @"wewe=23213123i18n("""", test. ),cstr(12),i18n("""",test3)hdsghwgdhwsgd)";
item = @"MsgBox(I18N(CStr(539)," + "Cannot migrate to the same panel type.)" +", MsgBoxStyle.Exclamation, DOWNLOAD_CAPTION)";
string reg1 = @"i18n(.*),(.*)\)";
string strVal = Regex.Match(item, reg1, RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase).Groups[0].Value;
List<string> str = new List<string> ();
str.Add(strVal);
System.IO.File.WriteAllLines(@"C:\Users\E543925.PACRIM1\Desktop\Tools\Test.txt", str);
}
}
}
Expected output - I18N(CStr(539)," + "Cannot migrate to the same panel type.)
Actual output - I18N(CStr(539),Cannot migrate to the samepaneltype.),MsgBoxStyle.Exclamation, DOWNLOAD_CAPTION)
我必须对正则表达式进行一些更改。我试过了,但没能成功。我是 regex 和 c# 的新手。请帮忙 。提前致谢 ..