Regex 正则表达式提取句子中的两个字符串
我希望提取下面的两个字符串以成为ABC-DEF。什么是好的正则表达式 位置之前的数据包=位置之后的ABC数据包=DEF尝试以下操作:Regex 正则表达式提取句子中的两个字符串,regex,Regex,我希望提取下面的两个字符串以成为ABC-DEF。什么是好的正则表达式 位置之前的数据包=位置之后的ABC数据包=DEF尝试以下操作: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace ConsoleApplication1 { class Program {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string input = "data-package-before-location=\"ABC\" data-package-after-location=\"DEF\"";
string pattern = @"(?'key'[\w-]+)=""(?'value'\w+)""";
MatchCollection matches = Regex.Matches(input, pattern);
foreach (Match match in matches.Cast<Match>())
{
Console.WriteLine("Key : '{0}', Value : '{1}'", match.Groups["key"].Value, match.Groups["value"].Value);
}
Console.ReadLine();
}
}
}
谢谢如何以非编程方式使用模式?我在下面测试了字符串模式,但在link上没有匹配。我将两个双引号替换为一个双引号。输入不需要双引号或反斜杠。该模式也不需要在开头和结尾使用符号和双引号。欢迎使用StackOverflow。请在参考后回顾您的问题。你需要出示一些证据,证明你曾尝试过与张贴的问题相关的问题。