String matching with matching delimiters 
Author Message
 String matching with matching delimiters

I have been doing a lot of work lately manipulating TeX files with perl. Is
there an easy way to give a pattern like:

   /\\hbox{ ... }/

Where the "..." includes everything up to the *matching* brace. This may
include closing braces, so "{[^}]+}" does not work. Presently, I loop through
the string counting opens and closes by hand... I don't think rexegp's are
powerful enough to do it alone, but in perl...

(Also, could rindex be enhanced to be able to match the right-most ocurrence
*before* a certain point? I.e. to be symmetrical with index.)
--




Sat, 18 Feb 1995 05:30:16 GMT  
 String matching with matching delimiters
: I have been doing a lot of work lately manipulating TeX files with perl. Is
: there an easy way to give a pattern like:
:
:    /\\hbox{ ... }/
:
: Where the "..." includes everything up to the *matching* brace. This may
: include closing braces, so "{[^}]+}" does not work. Presently, I loop through
: the string counting opens and closes by hand... I don't think rexegp's are
: powerful enough to do it alone, but in perl...

I've considered adding some kind of automatic tokenizing, but for now
you just have to s/// the front off the string and count brackets.  This
is really way beyond the capabilities of regular expressions.

: (Also, could rindex be enhanced to be able to match the right-most ocurrence
: *before* a certain point? I.e. to be symmetrical with index.)

Already does.  Try supplying a third argument.

Larry



Sun, 19 Feb 1995 05:26:35 GMT  
 String matching with matching delimiters

I had this exact problem when I was trying to write something that would
convert from ATK BE2 datastream format into{*filter*}(specifically, to convert
`eq' files to{*filter*}- instant pub-domain wysiwyg equation editor!)

Regexps are not powerful enough to do arbitrary nesting.  A push-down automaton
could do it, but that's my computability/complexity/automata course remnants
swimming around in my brain (which I could never put into Perl code).  Anycase,
I gave up eventually and used emacs-lisp code (forward-sexp, backward-sexp,
and kill-sexp) for what I needed.

If someone has code for this, I'd like to look at it both so I can write an
eq2latex.pl, and for the perl example experience.  Please mail me if you have
any replies.

Krishna Sethuraman



Sun, 19 Feb 1995 01:25:12 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Pattern Match - substitute a string after the match

2. Palindrome string matching (general match) ??

3. Matching balanced delimiters?

4. Matching only when not within delimiters.

5. string assignement vs string matching

6. Help with regex: How to match shortest match (Anno Siegel)

7. Help with regex: How to match shortest match

8. \([0-9]{3}\) matching but \b\([0-9]{3}\)\b is matching nothing,

9. matching matching quotes - efficiency wanted

10. match where 2 characters in a row don't match

11. Pattern bug matching whitespace in multi-line match?

12. combine two pattern matches to one match?

 

 
Powered by phpBB® Forum Software