---
title: "How to regex to check to find out items with given character?"  
description: "How to regex to check to find out items with given character?"  
author: "marcel ethan"  
published: 2015-01-27  
updated: 2015-01-27  
canonical: https://www.mindstick.com/forum/12906/how-to-regex-to-check-to-find-out-items-with-given-character  
category: "asp.net"  
tags: ["c#", "asp.net mvc", "regex"]  
reading_time: 1 minute  

---

# How to regex to check to find out items with given character?

I've a [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp)

```
public class MyClass        {            public MyClass(int id, string name)            {                this.Id = id;                //Id = id;                this.Name = name;            }            public int Id { get; set; }            public string Name { get; set; }        }
```

I created a list of MyClass type and added few [items](https://www.mindstick.com/forum/33812/getting-number-of-items-selected-in-uicollectionview-in-ios) to it

```
    List<MyClass> lst = new List<MyClass>();    lst.Add(new MyClass(1, "Name1"));    lst.Add(new MyClass(2, "ab****cdefg"));    lst.Add(new MyClass(3, "he*llo"));    lst.Add(new MyClass(4, "pa**yed"));    lst.Add(new MyClass(5, "Names2"));    lst.Add(new MyClass(6, "hi******iiii"));    lst.Add(new MyClass(7, "so*me"));    lst.Add(new MyClass(8, "so**rt"));    lst.Add(new MyClass(9, "*"));    lst.Add(new MyClass(10, "**"));    lst.Add(new MyClass(11, "t*e*s*t"));    lst.Add(new MyClass(12, "t**e**s**t"));
```

How can i find items having only one * in [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide) [field](https://www.mindstick.com/forum/160867/does-mindstick-provide-training-for-field-marketing) in a list and two ** in name field in another list. I'ld like to do it by [linq](https://www.mindstick.com/articles/12007/language-integrated-query-linq-queries) or [regex](https://www.mindstick.com/forum/160352/how-to-use-regex-in-javascript-for-pattern-matching), any other good [option](https://www.mindstick.com/forum/159391/jquery-get-selected-option-from-dropdown) is also invited. I tried using containsmethod but got all items having *.

[var](https://www.mindstick.com/forum/33920/what-is-different-var-and-dynamic-types-in-c-sharp) singlestar = lst.Where(x => x.Name.Contains("*")).ToList();

## Replies

### Reply by Samuel Fernandes

this should match names with just one "\*" and two "\*\*"

var singlestar = lst.Where(x =>Regex.Matches(x.Name, "\\*").Count == 1).ToList();

var twostar = lst.Where(x =>Regex.Matches(x.Name, "\\*\\*").Count == 1).ToList();


---

Original Source: https://www.mindstick.com/forum/12906/how-to-regex-to-check-to-find-out-items-with-given-character

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
