c# - Ignoring ' (apostrophe) from RegEx -


i've regex , ignore ' (apostrophe) within string. regex discussion can found within discussion string manipulation: how replace string specific pattern

regex: \\(\\s*'(?<text>[^'']*)'\\s*,\\s*(?<pname>[\\w\\[\\]]+)\\s*\\) 

basically provided regex doesn't work in scenario {text} contains ' (apostrophe). can please have regex ignore apostroph'e within {text}?

for eg:   substringof('b's',name) should replaced name.contains("b's")  substringof('b'',name) should replaced name.contains("b'") substringof('''',name) should replaced name.contains("'") 

appreciate it!! thank you.

it seems difficult deal case ''''. it's reason why choose use delegate , replace solve issue.

static void main(string[] args) {     var subjects = new string[] {"substringof('xxxx',name)", "substringof('b's',name)", "substringof('b'',name)", "substringof('''',name)"};      regex reg = new regex(@"substringof\('(.+?)'\s*,\s*([\w\[\]]+)\)");     foreach (string subject in subjects) {         string result = reg.replace(subject, delegate(match m) { return m.groups[2].value + ".contains(\"" + m.groups[1].value.replace("''", "'") + "\")"; });         console.writeline(result);     } } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -