.net - Regex that matches a newline (\n) in C# -
OK, this is driving me crazy .... I have a string that is made like this:
var newContent = string.Format ("({0}) \ n {1}", tampered content, answer)
New content will be displayed:
(old text) New text
I need a regular expression which removes the text between brackets with brackets and the text with new letters.
The best I can come up with is:
const string regex = @ "^ (\ (. * \) \ S)? (? & Quot; Capture & Gt ;. *) "; Var Match = Reggae Match (original_content, regex); Var stripped_content = match Group ["capture"]. Values;
This works, but I want to match the new line ( \ n
) specifically, any empty space ( \ s
) is not changing with \ s
with \ n
\\ n
or \\\ n
Does not work.
Please help capture my discretion!
Edit: An example:
public string reply (string old, string new) {const string regex = @ "^ (\ (* \)) .)? (& Quot; capture & gt ;. *) "; Var Match = Reggae Match (old, reggae); Var stripped_content = match Group ["capture"]. Values; Var result = string.format ("({0}) \ n {1}", teased content, new); Return result; } Answer ("(message one) \ nmessageTwo", "messageThree"): (messageTwo) message three
If you specify RegexOptions.Multiline, you can use ^
and $
to match the start and end of a line, respectively Are there.
If you do not want to use this option, then remember that a new row can be any of the following: \ n
, \ r < / Code>,
\ r \ N
, so instead of just looking for \ n
, you might want to use something like this: [\ n \ r] +
, or more at all: (\ n | \ r \ n \ r \ n)
.
Comments
Post a Comment