Note that there are some explanatory texts on larger screens.

plurals
  1. POPerl regex choking on multiple instances of character sets
    text
    copied!<p>I started out with some crazy failures using preg_replace in php and boiled it down to the problem case of having more than one character class using turkish dotted "i" and undotted "ı" together. Here is a simple test case in php:</p> <pre><code>&lt;?php echo 'match single normal i: '; $str = 'mi'; echo (preg_match('!m[ıi]!', $str)) ? "ok\n" : "fail\n"; echo 'match single undotted ı: '; $str = 'mı'; echo (preg_match('!m[ıi]!', $str)) ? "ok\n" : "fail\n"; echo 'match double normal i: '; $str = 'misir'; echo (preg_match('!m[ıi]s[ıi]r!', $str)) ? "ok\n" : "fail\n"; echo 'match double undotted ı: '; $str = 'mısır'; echo (preg_match('!m[ıi]s[ıi]r!', $str)) ? "ok\n" : "fail\n"; ?&gt; </code></pre> <p>And the same test case again in perl:</p> <pre><code>#!/usr/bin/perl $str = 'mi'; $str =~ m/m[ıi]/ &amp;&amp; print "match single normal i\n"; $str = 'mı'; $str =~ m/m[ıi]/ &amp;&amp; print "match single undotted ı\n"; $str = 'misir'; $str =~ m/m[ıi]s[ıi]r/ &amp;&amp; print "match double normal i\n"; $str = 'mısır'; $str =~ m/m[ıi]s[ıi]r/ &amp;&amp; print "match double undotted ı\n"; </code></pre> <p>The first three tests work fine. The last one does not match.</p> <p>Why does this work fine as a character class once but not the second time in the same expression? How do I write an expression to match for a word like this that needs to match no matter what combinations of letters it is written with?</p> <p><strong>Edit:</strong> Background on <a href="http://www.i18nguy.com/unicode/turkish-i18n.html#problem" rel="nofollow">the language problem</a> I'm trying to program for.</p> <p><strong>Edit 2:</strong> Adding a <code>use utf8;</code> directive does fix the perl version. Since my original problem was with a php program and I only switched to perl to see if it was a bug in php, that doesn't help me a whole lot. <em>Does anybody know the directive to make PHP not choke on this?</em></p>
 

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