A group with ?:
is a non capturing group meaning it would not be included in the result.
//Will match a "WriteLine" or "Write", but will ignore the Line in the result
Write(?:Line)?
//*match* -> *captured as*
//WriteLine -> Write
//Write -> Write
//Will match a "WriteLine" or "Write"
Write(Line)?
//*match* -> *captured as*
//WriteLine -> WriteLine
//Write -> Write
Regex for the #2
Correct me if I didn't understand correctly.
If you want to replace Int
or Tntl
with International
, do this :
var result = Regex.Replace("International:Int,Tntl,International","(Int(ernational)?|Tntl)","International");
// "International:Int,Tntl,International" ->
// "International:International,International,International"
The pipe symbol |
serve as or
operator for the regular expression.
(International|Int|Tntl)