问题描述:

I am trying to get rid of the delimited text.

For Example: "this#101# is#102# a#103# test#104#"

Result : "this is a test"

Tried the Following which didn;t Work

string Pattern = @"(?<=#).*(?=#;)";

string text = "this#101# is#102# a#103# test#104#";

text = Regex.Replace(text, Pattern, string.Empty);

网友答案:

Try:

string Pattern = @"#.*?#";

Since you need to get rid of the # too, you need to specify them as matching part of the regex. Your current regex does not match the #.

Also you need to make the .* match non-greedy by adding a trailing ?.

相关阅读:
Top