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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -