-2

I need help fixing the regular expression below. I tried to rewrite it from Python to C#, but C# displays empty m.value. Thanks!

In Python it works well and displays brackets and inside contents:

Python Code:

r1="(dog apple text) (grape cushion cat)"
a=re.findall("[(]+[/s]+[a-z]+[)]+",r1)
print(a[:]) 
//Conent gives me (dog apple text) (grape cushion cat) , so if I will call print(a[0]) it will give me (dog apple text)

 String r1="(dog apple text) (grape cushion cat)"
    String pat=@"[(]+[/s]+[a-z]+[)]+";

      foreach (Match m in Regex.Matches(irregv, pat2))
                {                  
                    Console.WriteLine("'{0}'", m.Value);                             
                }
Jack
  • 15,582
  • 17
  • 86
  • 162
Rr1n
  • 121
  • 1
  • 2
  • 9
  • 2
    `/s` should be `\s` but even then your expression would match things like `(((((( hello))` rather than anything in your example. You'd be best off starting out with some tutorials - http://regular-expressions.info has a lot of good info with examples. Also worth checking out [Reference - What does this regex mean?](http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) on SO. – OGHaza May 21 '14 at 09:32

1 Answers1

2

Your regex doesn't work in python either.

You want to use:

\([a-z\s]+\)

\( matches one opening bracket, [a-z\s] allows letters (lowercase) and any sort of whitespaces through \s (notice the anti-slash).

See (and play with) demo here.

Robin
  • 8,479
  • 2
  • 30
  • 44