in reply to Search and replace again

What have you tried? What didn't work? See How do I post a question effectively?.

When dealing with XML, it's generally easier to use pre-rolled solutions like XML::Simple or XML::Twig; however, you can accomplish your goal with character classes - note this assumes that > does not occur in string context - I don't remember what characters are valid in attribute strings:

my $string = '<image attrib="one" attrib2="two" scope="local"/>'; $string =~ s/(<image\s[^>]*?)scope="local"/$1/g; print "$string\n"; __END__ <image attrib="one" attrib2="two" />

See perlretut for more info on character classes.

Replies are listed 'Best First'.
Re^2: Search and replace again
by ikegami (Patriarch) on Apr 19, 2010 at 21:52 UTC
    use strict; use warnings; use XML::Twig qw( ); binmode STDOUT; my $t = XML::Twig->new( twig_handlers => { 'image[@scope="local"]' => sub { $_->del_att('scope'); }, }, ); $t->parsefile($ARGV[0]); $t->flush();