in reply to Re^2: Regex with HTML::Entities
in thread Regex with HTML::Entities
Don't know what to tell you other than try providing a SSCCE that can actually be run. This below works as I expect it so you're doing something strange or (entirely possible) your problem statement's being misread.
(Also the <code> formatting is doing weird things but I actually have literal ✶ in my source and the output where it's being replaced with the entity below everywhere save the initialization of $wonky_char. Not sure what's the right way to get literal UTF8 chars in sample code using utf8.)
#!/usr/bin/env perl use 5.034; use HTML::Entities qw( decode_entities ); use utf8; my $input = qq{{✶Adjektive (Nominalflexion)~87✶}}; my $wonky_char = decode_entities( q{✶} ); binmode( STDOUT, q{:utf8} ); say qq{\$input: $input}; say qq{\$wonky_char: $wonky_char}; my $to_match = "Adjektive (Nominalflexion)~87"; my $new_string = $input =~ s{\{$wonky_char(\Q$to_match\E)$wonky_char\}}{<div>I found +'$1'</div>}r; say qq{\$new_string: $new_string}; my $cleaner_regex_sample = $input =~ s{ \{ $wonky_char (\Q$to_match\E) $wonky_char \} }{<div>Al +so found '$1'</div>}rx; say qq{cleaner: $cleaner_regex_sample}; exit 0; __END__ $input: {✶Adjektive (Nominalflexion)~87✶} $wonky_char: ✶ $new_string: <div>I found 'Adjektive (Nominalflexion)~87'</div> cleaner: <div>Also found 'Adjektive (Nominalflexion)~87'</div>
The cake is a lie.
The cake is a lie.
The cake is a lie.
|
|---|