【发布时间】:2014-01-06 23:30:00
【问题描述】:
我有以下字符串:
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
这里出了点问题...感谢帮助。
【问题讨论】:
标签: c# regex asp.net-mvc