regex to find all occurences between two small brackets in c#

Priya
Priya
1194 Points
33 Posts

How to find all occurences in between each small brakets '(..)' in c#?

Views: 173
Total Answered: 2
Total Marked As Answer: 1
Posted On: 18-Jan-2024 23:45

Share:   fb twitter linkedin
Answers
Jak
Jak
908 Points
132 Posts
         

We can use regexp as following:

var allMatches = Regex.Matches("(first)asdf(second)", @"(?<=\().+?(?=\))");
foreach (var item in allMatches.ToList())
{
     Console.WriteLine(item);
}

Need to include following packages:

using System.Text;
using System.Text.RegularExpressions;

 

Posted On: 23-Jan-2024 05:51
thnaks
 - Priya  26-Jan-2024 04:48
b_r
b_r
12 Points
1 Posts
         

We can use following regex for getting all occurances:

Regex.Matches("(first)as(df(second))", @"\(([^()]+)\)")
Posted On: 30-Jan-2024 07:46
 Log In to Chat