I have sentencesthose designs with wordsand digits. I want to get stringthat comprise 1st charof all word, all digitand the word has a all upper casecapital letter. I tried using Regex, but the problem is that it does not give letters all digitand all upper case.
My Regex is located in Regex101 .
My solution is in DotNetFiddle .
CODE:
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
List<string> list = new List<string> {"Freestyle steel","Freestyle Alloy","Trekking steel uk","Single speed","5 speed","15 speed","3 Speed internal gear with 55 coaster","MTB steel","Junior MTB"};
foreach(string data in list)
{
string regex = @"(\b\w)|(\d+)";
var matches = Regex.Matches(data, regex, RegexOptions.Multiline);
string output = "";
foreach(Match item in matches)
{
output += item.Groups[1];
}
Console.WriteLine(output);
}
}
}
Input example
Free steel
Freestyle Alloy
Marching steel uk
Single speed
5 speeds
15 speed
3 Speed Internal Gear with 55 Coaster
Steel MTB
Junior MTB
Sample output
Fs
F
Tsa
Ss
5s
15s
3Sigw55c
torpedo boats
Jmtb