[Solved] How to crop strings using regular expressions? [closed]


If you want to use Regex, you can use the following.

"( |:).*"

Example,

var list= @"Summoner1 joined the lobby.
Summoner2 jonied the lobby.
Summoner3: Top
Summoner4: ADC";


var result = list.Split(new []{Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Select(x=> Regex.Replace(x,"( |:).*",string.Empty));

Update: Based on Comment

var result = string.Join("|",list.Split(new []{Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Select(x=> Regex.Replace(x,"( |:).*",string.Empty)));

Output

Summoner1|Summoner2|Summoner3|Summoner4

7

solved How to crop strings using regular expressions? [closed]