c# - Remove a character in a string, provided it is enclosed by brackets -
in advance, haven't learned regex yet (though i'm happy use 1 if supply it).
i have strings this:
"zum abschluss kommen (nachdrücklich; abgeschlossen werden)".
what want replace character ;
:
whenever occurs somewhere in brackets(). ie: want string end
"zum abschluss kommen (nachdrücklich: abgeschlossen werden)".
the thing causing me trouble there amount of text within brackets usual (clumsy) string manip not helping me.
extra example:
"alle mann deck! (seemannsspr.; ein kommando)"
->
"alle mann deck! (seemannsspr.: ein kommando)"
i can't replace() because full strings contain ;
want keep. eg:
"das deck reinigen, scheuern; auf deck sein; unter, von deck gehen; alle mann deck! (seemannsspr.; ein kommando);"
got suggestions?
with restriction parenthesis/brackets not nested or unbalanced, consider regular expression uses positive look-behind.
this behind ensures there leftward (
closer )
, must inside bracket set:
(?<=[(][^)]*);
in use:
regex.replace(input, @"(?<=[(][^)]*);", ":");
if initial constraints not valid, regular expression work "unpredictably".
Comments
Post a Comment