Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ability to match balanced parentheses using string patterns / regular

7 views
Skip to first unread message

dnquark

unread,
Jul 2, 2009, 7:13:38 AM7/2/09
to
I am curious, does Mathematica have the capability to match strings
involving balanced parentheses? In particular, would it be possible
to translate the following Perl code into Mathematica?
#!/usr/bin/perl
my $bal;
$bal = qr /[(] # match opening paren
[^()]* # match stuff that doesn't involve
parens
(?:(??{ $bal }) [^()]* )* # matched balanced parens + non-
# parens characters
[)]/x; # match closing paren
# usage example: replace the argument to sqrt() function, where the
argument is a string containing balanced
# parens
s/(sqrt)( (??{ $bal }) )/Sqrt\[\2\]/gx;

0 new messages