Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Thanks for your solutions seems to work in that example and also and more I try. The $4 seems not to be necessary, at least in my case returns only three results. An example code that works with your suggestions:
#!/usr/bin/perl use strict; use warnings; use POSIX qw(locale_h); my $old_locale = setlocale(LC_CTYPE); setlocale(LC_CTYPE, 'ca_ES.iso885915@euro'); use locale; my @expressions; my @contents; my $content = qq{ Abbott test1 test2 salud }; push (@contents, $content); $content = qq{ salud test1 test2 Abbott }; push (@contents, $content); $content = qq{ Abbott test1 test2 test2 test2 test2 test2 test2 test2 test2 salud }; push (@contents, $content); $content = qq{ salud test1 test2 test2 test2 test2 test2 test2 test2 test2 Abbott }; push (@contents, $content); $content = qq{ salud test1 test2 test2 test2 test2 test2 test2 test2 test2 test2 +Abbott }; push (@contents, $content); $content = qq{ Abbott test1 test2 test2 test2 test2 test2 test2 test2 test2 test2 + salud }; push (@contents, $content); $content = qq{ salud test1 test2 test2 test2 test2 test2 test2 test2 test2 test2 +test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 Abbott }; push (@contents, $content); $content = qq{ salud test1 test2 test2 test2 test2 test2 test2 test2 test2 test2 +test2 test2 test2 test2 test2 test2 test2 test2 test2 Abbott }; push (@contents, $content); $content = qq{ salud test1 test2 test2 test2 test2 test2 test2 test2 test2 test2 +test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 Abbott }; push (@contents, $content); $content = qq{ salud Abbott test1 test2 salud }; push (@contents, $content); my $par1 = '[a\xe0\xe1\xe4\xe2A\xc1\xc0\xc4\xc2]bb[o\xf2\xf3\xf6\xf4O\ +xd3\xd2\xd6\xd4]tt'; my $par2 = 's[a\xe0\xe1\xe4\xe2A\xc1\xc0\xc4\xc2]l[u\xf9\xfa\xfc\xfbU\ +xda\xd9\xdc\xdb]d'; my $expression = "$par1 $par2\:\:20"; push (@expressions, $expression); warn "PART 1"; foreach my $cont (@contents){ warn "CONTENT $cont"; foreach my $exp (@expressions) { my $tag = 'span'; my $class = "lighligth"; next if ($exp !~ /::/); my ($exp, $distance) = split("::", $exp); my ($par1, $par2) = split(' ', $exp); # warn "Pars $par1 - $par2 - $distance"; if ($cont =~ /$par1.*$par2/i) { if ($cont =~ /\b($par1)(\W+(?:\w+\W+){0,$distance})($par2)\b +/i) { # if ($cont =~ m/\b($par1)(\W+(?:\w*\W*){1,$distance})?($p +ar2)\b/i){ my ($par1, $par2, $par3, $par4) = ($1, $2, $3, $4); warn "FIND 1 Par1: $par1 Par2: $par2 Part3: $par3"; $cont =~ s/$par1\Q$par2\E$par3/<$tag$class> $par1<\/$tag> +$par2<$tag$class> $par3<\/$tag>/gi; } } warn "STEP"; if ($cont =~ /$par2.*$par1/i) { if ($cont =~ /\b($par2)(\W+(?:\w+\W+){0,$distance})($par1)\b +/i) { my ($par1, $par2, $par3, $par4) = ($1, $2, $3, $4); warn "FIND 2 Par1: $par1 Par2: $par2 Part3: $par3"; $cont =~ s/$par1\Q$par2\E$par3/<$tag$class> $par1<\/$t +ag>$par2<$tag$class> $par3<\/$tag>/gi; } } } warn "END"; warn "\n\n"; }

In reply to Re^4: Problems searching and highlighting proximity words in a text by jrc
in thread Problems searching and highlighting proximity words in a text by jrc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (5)
    As of 2015-07-08 02:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (93 votes), past polls