KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
OK, this one is driving me nuts.... I have a string that is formed thus: var newContent = string.Format("({0})\n{1}", stripped_content, reply) newContent will display like: (old text) new text I need a regular expression that strips away the text between parentheses with the parenthesis included AND the newline character. The best I can come up with is: const string regex = @"^(\(.*\)\s)?(?<capture>.*)"; var match= Regex.Match(original_content, regex); var stripped_content = match.Groups["capture"].Value; This works, but I want specifically to match the newline ( \n ), not any whitespace ( \s ) Replacing \s with \n \\n or \\\n does NOT work. Please help me hold on to my sanity! EDIT: an example: public string Reply(string old,string neww) { const string regex = @"^(\(.*\)\s)?(?<capture>.*)"; var match= Regex.Match(old, regex); var stripped_content = match.Groups["capture"].Value; var result= string.Format("({0})\n{1}", stripped_content, neww); return result; } Reply("(messageOne)\nmessageTwo","messageThree") returns : (messageTwo) messageThree
Tags (comma-separated)
Save Edits
Cancel