Regular expression for extracting arguments

I am trying to extract arguments from a call function of type string, for example:

GetStatus("Param1", "Param2", "ParamWith\"Quotations\"")

I am useless for regular expressions, but is it possible to match these parameter values ​​in this way, including escaped quotes?

i.e. Param1, Param2, ParamWith "Quotes"

Even better, is there a way to extract the function name and only arguments if parentheses and arguments are present?

I use C # if that matters.

+3
source share
3 answers

You can split and crop (to get the function name.

: ?. . LB , , .

, , , . , , , . , , Unix- (.. -options " " ), Regex:

Regex reg = new Regex("\".*?\"")

. "," . , , , , .

, "GetStatus (Param1, Param2, ParamsWith \" Quotations\ ")" , , ", " ".

+1

String.split '(', , ',',

EDIT: , , . :

  • , '('.
  • , '('
  • " , ".\ " \\ . - " " , (, , ). .
  • , ',' '' '' '. ",", 2. ")" .
0

, ,

string fxn = @"GetStatus(""Param1"", ""Param2"", ""ParamWith\""Quotations\"""")";

var result = Regex.Matches(fxn, @"\""(?<GRP>[\w \\\""]+)\""|(?<GRP>\w+[ ]*)")
    .Cast<Match>()
    .Select(m => m.Groups["GRP"].Value)
    .ToArray();
0

All Articles