iaw4 has asked for the wisdom of the Perl Monks concerning the following question:
I really want/usr/bin/perl -w use strict; use warnings; use re 'eval'; use Regexp::Common; my $text= "start \\chapter{argument1}{argument2} end"; print "INPUT: $text\n"; ################################################################ my $arg1= qr/\s*($RE{balanced}{-parens=>'{ }'})/; my $args2= $arg1.$arg1; my $macronamereadfromfile="chapter"; my $patternreadfromfile= "<h1 tag=\"\$2\">\$1</h1>"; my $inpattern = "\\\\$macronamereadfromfile$args2"; my $outpattern = qq{ qq{$patternreadfromfile} }; #print "PATTERNS: '$inpattern'. to='$patternreadfromfile'. became='$ +outpattern'\n"; $text =~ s/$inpattern/$outpattern/gee; ################################################################ print "OUTPUT: '$text'\n\n";
and notOUTPUT: 'start <h1 tag="argument1">argument1</h1> end'
I could replace my pattern with a really unusual surrounding string in step 1 (e.g., @@$1@@) and then remove all '@@{' and '}@@' but this seems very ugly. there must be a simpler way. advice appreciated. regards, /iawOUTPUT: 'start <h1 tag="{argument1}">{argument1}</h1> end'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regexp::Common balanced curlies substitution
by kyle (Abbot) on Aug 16, 2008 at 03:09 UTC | |
|
Re: Regexp::Common balanced curlies substitution
by JavaFan (Canon) on Aug 16, 2008 at 09:52 UTC | |
|
Re: Regexp::Common balanced curlies substitution
by massa (Hermit) on Aug 16, 2008 at 02:59 UTC | |
by kyle (Abbot) on Aug 16, 2008 at 03:12 UTC | |
|
Re: Regexp::Common balanced curlies substitution
by hexcoder (Curate) on Aug 16, 2008 at 14:18 UTC | |
|
Re: Regexp::Common balanced curlies substitution
by AnomalousMonk (Archbishop) on Aug 16, 2008 at 19:26 UTC |