lundi 23 février 2015

Check if string equals (at least the first 2 letters) and containing a number

I've a list with some Strings, want to compare the strings and save the matching strings in a new list.


Matching means, that:



  • the first 2 characters have to be letters

  • the letters (at least the first 2 letters) have to be equal

  • and it have to appear a number after the equal letters





List<String> items = new List<string>()
{
"ne1234",
"ne2abc",
"type",
"12345"
"12346"
"s0",
"s1",
"numb4er",
"numb5er",
"numb8er",
"tax1-0",
"tax1-1"
};

List<String> equalitems = new List<string>();




Content of equalitems



  • ne*

  • numb*

  • tax*


I can't find a good approach to solve this. Has somebody an idea?


Aucun commentaire:

Enregistrer un commentaire