g_speran has asked for the wisdom of the Perl Monks concerning the following question:

Wondering if someone can put eyes on this and tell me what i am doing incorrectly. I've tried several option but make it worse

Hoping someone can quickly spot my error.

i need to get rid of the doublequotes after 'value=' and before '/>'

Thanks in advance

my $content = '<entry key="maxcompdatastripe" value="41943040" />'; my $maxreplacement_value = ' "20917520" merge="keep" '; $content =~ s/(<entry key="maxcompdatastripe" value=")[^"]*("\s*\/>)/$ +1$maxreplacement_value$2/g; print "Content: $content\n"; Expected results: <entry key="maxcompdatastripe" value="20917520" merge="keep" /> Actual Results: Content: <entry key="maxcompdatastripe" value=" "20917520" merge="keep +" " />

Replies are listed 'Best First'.
Re: Regular Expression Assistance
by choroba (Cardinal) on Jun 19, 2024 at 18:11 UTC
    XML is better handled by an XML-aware tool.
    #!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use XML::LibXML; my $content = '<entry key="maxcompdatastripe" value="41943040" />'; my $entry = 'XML::LibXML'->load_xml(string => $content)->documentEleme +nt; $entry->{value} = '20917520'; $entry->{merge} = 'keep'; say $entry;

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: Regular Expression Assistance
by jdporter (Paladin) on Jun 19, 2024 at 16:49 UTC
Re: Regular Expression Assistance
by g_speran (Scribe) on Jun 19, 2024 at 17:07 UTC

    I have figured this out

    $content =~ s/(<entry key="maxcompdatastripe" value)="([^"]*)"\s*\/>/$ +1=$maxreplacement_value\/>/;