Consider the below
Case 1: SDN#(X,)
Case 2: SDN#(X,12)
Case 3: SDN#(34,12)
Case 4: CORR#(X,,)
Case 5: CORR#(X,12,45)
Case 6: CFH#(X,AVG)
These all are some kind of custom functions.
How can I build a regular expression that will identity that the given text satisfies the function requirement
The generalised structure is as <FUNCTION NAME>#(arg1,[arg2],[agr3]….)
e.g. given CORR, or CORR#() it is not a funciton.
Because every function must have atleast one argument(which will be alphanumeric).
My approach so far is
Regex r = new Regex(@"([A-Z]+)[#]([A-Z a-z 0-9]+),([A-Z a-z 0-9]+),([A-Z a-z 0-9]+)");
Match m = r.Match(txtFunction.Text);
if (m.Success) MessageBox.Show("OK");
else MessageBox.Show("Not OK");
But it is not working
I am using C#3.0
Thanks
Here’s an attempt (even if I don’t know if its working in C#):
Explanation: using
CORR#(arg1, arg2, arg3)[A-Z]+#matches the function name, hereCORR#\(matches the opening parentheses(. Note that I escaped the(in order to tell the engine not to take it as a grouping construct.([A-Za-z0-0]+,?)*matchesarg1, arg2,. Note that it’s a bit hacky because of the,?which indicates that there might be a,at the end, but it is not necessary.,*matches “empty commata”.\)matches the closing parentheses. Note that I escaped the)in order to tell the engine not to take it as a grouping construct.