I would like to make a pattern using regex

I would like to make a regex pattern ,I would like to make a pattern that get the value which is inside the brackets ,I tried this one but its not working.

String input = "(3+4)+5*4";
Match m = Regex.Match(input, @"([(0-9\/\+\-\*0-9)])");
if (m.Success)
{
    String value = m.Groups[1].ToString();
    MessageBox.Show(value);
}

Answers


what you are doing is mis-understanding what a "class" does in a regular expression.

[] - Denotes a set of characters to match.  This is NOT a pattern.

what you need to be grabbing is the pattern, which you did have nearly correct.

(\([0-9][\/\+\-\*][0-9]\))

Capture:
  Open Parenthesis
  Any character in [0-9]
  Any Character in [\/\+\*\-]
  Any Character in [0-9]
  Close Parenthesis

This will only allow one digit though. If you have ANY multi digit number, even a 10...this wont work. Now, if you changed it to something like this:

(\([0-9]+[\/\+\-\*][0-9]+\))

those + tell the regex to capture One or More. This will allow any number, not just a single digit.


Need Your Help

Using docker-compose in order to create a MySQL schema/database

mysql docker docker-compose

I am trying to create a mysql database/schema if it doesn't already exist.

NSTableView column editing with auto refresh of table

objective-c osx cocoa nstableview nstablecolumn

I have a NSTable that is being refreshed in each 5 seconds with new data. Now i have to add a new column to edit that user can edit. At the first time it is working edit column becomes un editable ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.