是否可以使用正则表达式返回 2 个字符串之间的字符串?例如,如果我有这个字符串:
string = "这是一个::::测试???字符串";
我可以编写一个函数来使用正则表达式返回单词“test”吗?
编辑:抱歉,我正在使用 C#
最佳答案
既然你没有提到语言,一些C#:
string input = "this is a :::test??? string";
Match match = Regex.Match(input, @":::(\w*)\?\?\?");
if (match.Success)
{
Console.WriteLine(match.Groups[1].Value);
}
(确切的正则表达式模式取决于你认为匹配的是什么......一个词?任何东西?等等......)
关于c# - 两个值之间的正则表达式返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1290538/