Matching when the part in paranthesis must be a number;
string inputstring="Likes (20)" Regex reg=new Regex(@"\((\d+)\)") string num= reg.Match(inputstring).Groups[1].Value
Explanation: By definition, regexp corresponds to a substring, so unless you specify otherwise, the string you are looking for can occur anywhere in your string.
\ d stands for numbers. It will match any single digit.
We want this to potentially be repeated several times, and we want at least one. The + sign is a regular expression for a previous character or group that is repeated 1 or more times.
So, \ d + will match one or more digits. It will match 20.
To make sure that we get a number that is in paranteses, we say that it should be between (and). These are special characters in regexp, so we need to avoid them.
(\ d +) would correspond to (20), and we are almost there.
Since we want the part inside the brackets, and not including the brackets, we tell regexp that the part of the digits is a separate group.
We do this using brackets in our regular expression. ((\ d +)) will still match (20), but now it will be noted that 20 is a subgroup of this match, and we can get it from Match.Groups [].
For any line in parentheses, things get a little more complicated.
Regex reg=new Regex(@"\((.+)\)")
Will work for many lines. (dot matches any character). But if the input signal looks like βThis is an example (parantesis1) (parantesis2)β, you would have to match (parantesis1) (parantesis2) with parantesis1) (parantesis2 as a captured subgroup. Be what you need.
The solution may be to match for "any character other than the closing particle"
Regex reg=new Regex(@"\(([^\(]+)\)")
This will find (parantesis1) as the first match with parantesis1 as .Groups [1].
It will still fail for nested parenteza, but since regular expressions are not the right tool for nested parenteza, I feel this case is a bit out of scope.
If you know that a line always starts with "Likes" in front of the group, then it is better to save the solution.