Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to match string with diacritic in perl?
    text
    copied!<p>For example, match "Nation" in ""Îñţérñåţîöñåļîžåţîöñ" without extra modules. Is it possible in new Perl versions (5.14, 5.15 etc)? </p> <blockquote> <p>I found an answer! Thanks to <strong>tchrist</strong></p> </blockquote> <p>Rigth solution with UCA match (thnx to <a href="https://stackoverflow.com/users/471272/tchrist">https://stackoverflow.com/users/471272/tchrist</a>).</p> <pre><code># found start/end offsets for matched utf-substring (without intersections) use 5.014; use strict; use warnings; use utf8; use Unicode::Collate; binmode STDOUT, ':encoding(UTF-8)'; my $str = "Îñţérñåţîöñåļîžåţîöñ" x 2; my $look = "Nation"; my $Collator = Unicode::Collate-&gt;new( normalization =&gt; undef, level =&gt; 1 ); my @match = $Collator-&gt;match($str, $look); if (@match) { my $found = $match[0]; my $f_len = length($found); say "match result: $found (length is $f_len)"; my $offset = 0; while ((my $start = index($str, $found, $offset)) != -1) { my $end = $start + $f_len; say sprintf("found at: %s,%s", $start, $end); $offset = $end + 1; } } </code></pre> <p>Wrong (but working) solution from <a href="http://www.perlmonks.org/?node_id=485681" rel="nofollow noreferrer">http://www.perlmonks.org/?node_id=485681</a></p> <blockquote> <p>Magic piece of code is:</p> </blockquote> <pre><code> $str = Unicode::Normalize::NFD($str); $str =~ s/\pM//g; </code></pre> <blockquote> <p>code example:</p> </blockquote> <pre><code> use 5.014; use utf8; use Unicode::Normalize; binmode STDOUT, ':encoding(UTF-8)'; my $str = "Îñţérñåţîöñåļîžåţîöñ"; my $look = "Nation"; say "before: $str\n"; $str = NFD($str); # M is short alias for \p{Mark} (http://perldoc.perl.org/perluniprops.html) $str =~ s/\pM//og; # remove "marks" say "after: $str";¬ say "is_match: ", $str =~ /$look/i || 0; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload