1

I have a static class called DataHelper. It has a few methods, but all of them take a string literal (a stored procedure name) as a parameter, like so:

DataHelper.ExecuteProc("DBMaster.DatabaseConnections_SelectAll", null, CONN);

I would like lo go through a source file and extract the string portion of each of these calls. I am currently using:

DataHelper.*(?<=")(?:[^"]|"")*(?=")

but that matches the whole thing. Is there a way via regex to just get the string portion of the parameter list for this function?

5
  • What is the expected result? What kind of values can you expect inside? What is the code you are using? BTW, check this demo. Commented Jun 18, 2018 at 19:36
  • The string portion: "DBMaster.DatabaseConnections_SelectAll" Commented Jun 18, 2018 at 19:42
  • 1
    Try (?<=DataHelper\.ExecuteProc\(")[^\\"]*(?:\\.[^\\"]*)*. See live demo here regex101.com/r/i3AgFx/1 Commented Jun 18, 2018 at 19:43
  • Use (?<=DataHelper\.\w+\(\s*")[^"\\]*(?:\\.[^"\\]*)* Commented Jun 18, 2018 at 19:47
  • Did my suggestion work? Commented Jul 2, 2018 at 10:36

2 Answers 2

2

You could use a capturing group or to not have DataHelper.ExecuteProc in matching result put it in lookbehind:

(?<=DataHelper\.ExecuteProc\(")[^\\"]*(?:\\.[^\\"]*)*

See live demo here

Breakdown:

  • (?<= Start of positive lookbehind
    • DataHelper\.ExecuteProc\(" Match it but not consume it
  • ) End of lookbehind
  • [^\\"]*(?:\\.[^\\"]*)* Match string enclosed in double qoutation marks
Sign up to request clarification or add additional context in comments.

Comments

1

You can do it like this:

var pattern = "\bDataHelper\..+?\(\"(?<procedure>[^\"]*?)\"";
var result = Regex.Match(input, pattern).Cast<Match>().Select(x=> x.Groups["procedure"].Value).ToList();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.