我有以下字符串:
function(param1, param2, param3, param4, ..., paramN)
我需要一个正则表达式代码,将其解析为字符串数组:
function
param1
param2
param3
param4
.
.
.
paramN
我在网上尝试了几个例子,但似乎都对我无效。
[编辑]
按照建议进行操作仍然无法正常工作。请检查上述代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace TestRegex
{
class Program
{
static void Main(string[] args)
{
string Expression = String.Empty;
while (Expression.Trim() != "EXIT")
{
Expression = Console.ReadLine();
///
/// Get function name
///
var funcTags = Regex.Matches(Expression, @"b[^()]+\((.*)\)$");
Console.WriteLine("Matches: " + funcTags.Count);
foreach (var item in funcTags)
Console.WriteLine("FuncTag: " + item);
///
/// Get parameters
///
var paramTags = Regex.Matches(Expression, @"\b[^()]+\((.*)\)$");
Console.WriteLine("Matches: " + paramTags.Count);
foreach (var item in paramTags)
Console.WriteLine("ParamTag: " + item);
}
}
}
}
输出:
function("a", "b", "c");
Matches: 0
Matches: 0
这里似乎有问题......感谢帮助。