c# - replace texts between specified tag in given string -
what best way replace text between tag [[ text ]] example "x" using regex |
for example:
this [[is]] text [[new text]]
and result have:
this x text x
i have triend that:
string pattern = @"\[\[(.*)\]\]"; regex rgx = new regex(pattern);
string input = "this [[is]] text [[new text]]"; string pattern = @"\[\[.+?\]\]"; var output = regex.replace(input, pattern, "x");
edit
what if want iterate through each matches
string pattern = @"\[\[(.+?)\]\]"; var matches = regex.matches(input, pattern) .cast<match>() .select(m => m.groups[1].value) .tolist();
or looking that
string pattern = @"\[\[(.+?)\]\]"; var output = regex.replace(input, pattern, m=>string.join("",m.groups[1].value.reverse()));
which return:
this si text txet wen
Comments
Post a Comment