是否可以使用正则表达式在两个字符串之间返回一个字符串?例如,如果我有这个字符串:
string ="这是一个::: test ??? 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);
}
Run Code Online (Sandbox Code Playgroud)
(确切的正则表达式取决于你认为匹配...一个字?什么?等等......)