下面是从文本框中获取字符串的代码:
string txtS = TextBoxS.Text;而不是使用regex提取一些文本:
string[] splitS=Regex.Split(txtS, @"\s(we|tomorow)\s");
text: Today we have a rainy day but maybe tomorow will be sunny.现在,在拆分之后,这给了我一个分裂点内的输出,OutPut:有一个未雨绸缪,但也许
但是用什么正则表达式来获得一个输出,包括分裂点或分隔符,so I want this output: we have a rainy day but maybe tomorow我尝试了一些其他正则表达式,但没有找到合适的表达式.
发布于 2022-11-18 21:05:24
C#代码将是:
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\s(we.+tomorow)\s";
string input = @"Today we have a rainy day but maybe tomorow will be sunny.";
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnoreCase;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("{0}", m.Value);
}
Console.ReadKey();
}
}

https://stackoverflow.com/questions/74495178
复制相似问题