function to match parenthesis '(' and ')'

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Kirsch

    #1

    function to match parenthesis '(' and ')'

    I need a simple function that can match the number of beginning and ending
    parenthesis in an expression. Here's a sample expression:

    ( ( "john" ) and ( "jane" ) and ( "joe" ) )

    Does .NET have something built-in that can accomplish this, or do I have to
    write my own parser? I don't want to reinvent the wheel if possible.



  • Cor Ligthert [MVP]

    #2
    Re: function to match parenthesis '(' and ')'

    Steve,

    Text.RegularExp ressions.Regex

    http://msdn.microsoft.com/library/de...classtopic.asp

    RegexLib


    Expresso


    By the way, I hate it to use every expression so this one too, however
    sometimes there are no good alternatives.

    I hope this helps a little bit?

    Cor


    Comment

    • Hollenho

      #3
      Re: function to match parenthesis '(' and ')'

      Steve,

      I'm not sure if this is what you want, but check out the "balancing groups"
      construction in .NET regular expressions. This feature can be used to search
      for matching parenthesis, but it is a bit arcane. It allows named captures
      to be manipulated on a push-down/pop-up stack. It can also be used to find
      matching HTML tags or any other nested construct.

      If you download Expresso (http://ultrapico.com), as suggested by Cor
      Ligthert, load the Tutorial and select example number 44 from the regular
      expression library. It will seach for a left parenthesis and then capture
      all the text up to the matching right parenthesis.

      This feature is very poorly documented in the Microsoft documentation. It is
      discussed in some detail in Jeffrey Friedl's excellent book. Chapter 9 of
      that book is available on line. See pat 430 for the section on "Matching
      Nested Constructs".

      http://www.oreilly.com/catalog/regex2/chapter/ch09.pdf

      I hope this helps.

      Jim

      "Steve Kirsch" <test@test.co m> wrote in message
      news:e$%23f9q01 FHA.1212@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      >I need a simple function that can match the number of beginning and ending
      > parenthesis in an expression. Here's a sample expression:
      >
      > ( ( "john" ) and ( "jane" ) and ( "joe" ) )
      >
      > Does .NET have something built-in that can accomplish this, or do I have
      > to
      > write my own parser? I don't want to reinvent the wheel if possible.
      >
      >
      >[/color]


      Comment

      Working...