Loading ...
Sorry, an error occurred while loading the content.

45657RE: Regexp help

Expand Messages
  • Srinath Avadhanula
    Dec 1, 2003
      On Tue, 2 Dec 2003, John Aldridge wrote:

      > At 22:30 12-01-2003, Srinath Avadhanula wrote:
      >
      > >Thanks for the answer. It was quite an eye-opener to know that
      > >parentheses balancing is unsolvable using regexps! On further googling,
      > >it looks like none of the common regexp engines can actually do this...
      >
      > For my curiosity, what were you hoping to do with such regexes?
      > Do you think you'll attempt a scripting solution?
      >
      I wanted a regexp solution for paren balancing specifically for use in
      the vim-latex project. I have a function which creates regexp based
      folds just like vim's native syntax foldmethod. That function requires
      a regexp start pattern and regexp end pattern to define the start and
      end of a fold region.

      The high level problem was to specify regexps to fold lines like:

      ------------------------%<------------------------
      \command{This is a command in latex \textbf{which}
      spans several lines and
      finally concludes \textbf{here}}
      ------------------------%<------------------------

      but avoid lines like

      ------------------------%<------------------------
      \command{This is a command in latex \textbf{which}}
      next line is not part of the command
      finally concludes \textbf{here}
      ------------------------%<------------------------

      As can be seen, the problem is to start a fold on a line which has
      unbalanced parentheses after the start of the command...

      It looks like checking whether a string has balanced parentheses or not
      is not really a difficult problem per se. Its just that the regexp
      solution is not possible. Unfortunately, I cannot use a parser based
      solution at the moment.

      Srinath
    • Show all 15 messages in this topic