c# - Trouble matching two occurrences of the same pattern using regex -
i've got sql query string, , i'm trying find , replace on using regex.
var s = "select ([document].[artifactid]) [document] (nolock) [document].[accesscontrollistid_d] in (1) , ((not exists(select codeartifactid codeartifact (nolock) associatedartifactid = [document].[artifactid] , codeartifact.codetypeid = 1000112))) "; //line breaks added readability
in order query work, need specify schema of [document] , codeartifact. have:
var pattern = "from\\s(?<table>\\s+)"; var replacepattern = "from eddsdbo.${table}"; var v = regex.replace(s, pattern, replacepattern); system.console.writeline(v);
but string i'm getting looks like:
select ([document].[artifactid]) [document] (nolock) [document].[accesscontrollistid_d] in (1) , ((not exists(select codeartifactid eddsdbo.codeartifact (nolock) associatedartifactid = [document].[artifactid] , codeartifact.codetypeid = 1000112)))
the codeartifact replaced, [document] not. must missing something. thoughts?
your code works me. issue can think of there's more 1 space between from
, [document]
in source code, in case can either remove space or use
from\\s+(?<table>\\s+)
Comments
Post a Comment