S
sln
Original message replied to was posted to perl.beginners
8-14, but it didn't show up. EasyNews is acting weird.
To test, I'm posting it here...
-sln
I saw this by chance
You should post this complex question to the clpm group.
Something in here should be of help. Don't know what though.
-sln
-------------------------
use strict;
use warnings;
# Require {[=+#?]} but not {}
my $open = '\{';
my $ctrl = '[=+#?]';
my $close = '\}';
my $regex = qr/
( # GRP 1
$open
( ($ctrl) ( # GRP 2, 3, 4
(?:
( # GRP 5
$open
(?:
(?>(??! $open$ctrl | $open | $close).)+)
| (?5)
)*
$close
)
|
(?>(??! $open$ctrl | $open | $close).)+)
| (?1)
)*
) ) # end GRP 2, 4
$close
)
/xs;
my $code = join '',<DATA>;
print "\n",'-'x10,"\nBefore:\n",'-'x10,"\n$code\n",'-'x10,"\n";
my $found = 0;
while ($code =~ /$regex/g) {
print "found: $1\n";
$found = 1;
}
if ($found) {
1 while ($code =~ s/$regex/"['$3'$4]"/eg);
print "\n",'-'x10,"\nAfter:\n",'-'x10,"\n$code\n";
}
__DATA__
I want to replace in a javscript structure like the one below every
occurence of "{#...}", "{?...}", "{+...}" and "{=...}" through
something different (also nested):
function() {
test1 = "{#Caption}";
test2 = "{#Te{?st{8}}}";
test3 = "{+date.{0}}";
}
8-14, but it didn't show up. EasyNews is acting weird.
To test, I'm posting it here...
-sln
Hi...
I want to replace in a javscript structure like the one below every
occurence of "{#...}", "{?...}", "{+...}" and "{=...}" through
something different (also nested):
function() {
test1 = "{#Caption}";
test2 = "{#Te{?st}}";
test3 = "{+date.{0}}";
}
with this regular expression
my( $open ) = qr/{[=+#?]/;
my( $close ) = qr/}/;
my( $not ) = qr/[^{}]++/;
do {
$found = $text =~ s/
(
$open
(?: $not | (?1) )
$close
)
/replace($1)/esxg;
} while ( $found );
I can handle case "test1" and "test2" but the case "test3" won't work.
Could some help me how I can change the expression that it match
"{+date.{0}}" without bothering about the "{0}" (this could also be
"{foo}").
I try it with:
my( $not ) = qr/(?>(??!$open)|(?!$close))+)/;
but that won't work.
Thanks and best regards. And please excuse my english, I hope you will
understand everything, otherwise ask me ;-)
T.
I saw this by chance
You should post this complex question to the clpm group.
Something in here should be of help. Don't know what though.
-sln
-------------------------
use strict;
use warnings;
# Require {[=+#?]} but not {}
my $open = '\{';
my $ctrl = '[=+#?]';
my $close = '\}';
my $regex = qr/
( # GRP 1
$open
( ($ctrl) ( # GRP 2, 3, 4
(?:
( # GRP 5
$open
(?:
(?>(??! $open$ctrl | $open | $close).)+)
| (?5)
)*
$close
)
|
(?>(??! $open$ctrl | $open | $close).)+)
| (?1)
)*
) ) # end GRP 2, 4
$close
)
/xs;
my $code = join '',<DATA>;
print "\n",'-'x10,"\nBefore:\n",'-'x10,"\n$code\n",'-'x10,"\n";
my $found = 0;
while ($code =~ /$regex/g) {
print "found: $1\n";
$found = 1;
}
if ($found) {
1 while ($code =~ s/$regex/"['$3'$4]"/eg);
print "\n",'-'x10,"\nAfter:\n",'-'x10,"\n$code\n";
}
__DATA__
I want to replace in a javscript structure like the one below every
occurence of "{#...}", "{?...}", "{+...}" and "{=...}" through
something different (also nested):
function() {
test1 = "{#Caption}";
test2 = "{#Te{?st{8}}}";
test3 = "{+date.{0}}";
}