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

Priya
Priya
Participant
936 Points
28 Posts

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

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

Share:   fb twitter linkedin
Answers
Jak
Jak
Member
858 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
0 Points
0 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