<p><a href="http://twitter.com/codinghorror/statuses/901272685" rel="nofollow noreferrer">Source</a></p>

<blockquote>
  <p>RegexOptions.IgnoreCase is more expensive than I would have thought (eg, should be barely measurable)</p>
</blockquote>

<p>Assuming that this applies to PHP, Python, Perl, Ruby etc as well as C# (which is what I assume Jeff was using), how much of a slowdown is it and will I incur a similar penalty with <code>/[a-zA-z]/</code> as I will with <code>/[a-z]/i</code> ?</p>

[{'answer_id': 32021, 'author': 'Jeff Atwood', 'author_id': 1, 'author_profile': 'https://Stackoverflow.com/users/1', 'pm_score': 5, 'selected': True, 'text': '<p>Yes, [A-Za-z] will be much faster than setting the <code>RegexOptions.IgnoreCase</code>, largely because of Unicode strings. But it\'s also much more limiting -- [A-Za-z] does <em>not</em> match accented international characters, it\'s literally the A-Za-z ASCII set and nothing more.</p>\n<p>I don\'t know if you saw Tim Bray\'s answer to my message, but it\'s a good one:</p>\n<blockquote>\n<p>One of the trickiest issues in internationalized search is upper and lower case. This notion of case is limited to languages written in the Latin, Greek, and Cyrillic character sets. English-speakers naturally expect search to be case-insensitive if only because they’re lazy: if Nadia Jones wants to look herself up on Google she’ll probably just type in nadia jones and expect the system to take care of it.</p>\n<p>So it’s fairly common for search systems to “normalize” words by converting them all to lower- or upper-case, both for indexing and queries.</p>\n<p>The trouble is that the mapping between cases is not always as straightforward as it is in English. For example, the German lower-case character “ß” becomes “SS” when upper-cased, and good old capital “I” when down-cased in Turkish becomes the dotless “ı” (yes, they have “i”, its upper-case version is “İ”). I have read (but not verified first-hand) that the rules for upcasing accented characters such “é” are different in France and Québec. One of the results of all this is that software such as java.String.toLowerCase() tends to run astonishingly slow as it tries to work around all these corner-cases.</p>\n</blockquote>\n<p><a href="http://www.tbray.org/ongoing/When/200x/2003/10/11/SearchI18n" rel="noreferrer">http://www.tbray.org/ongoing/When/200x/2003/10/11/SearchI18n</a></p>\n'}, {'answer_id': 32065, 'author': 'Vegard Larsen', 'author_id': 1606, 'author_profile': 'https://Stackoverflow.com/users/1606', 'pm_score': 1, 'selected': False, 'text': '<p>If you can tolerate having numbers and underscores in that regex, you can e.g. use the \\w modifier (Perl syntax). I believe some engines support [:alpha:], but that is not pure Perl. \\w takes into account the locale you are in, and matches both uppercase and lowercase, and I bet it is faster than using [A-Z] while ignoring case.</p>\n'}, {'answer_id': 32135, 'author': 'Nathan Fellman', 'author_id': 1084, 'author_profile': 'https://Stackoverflow.com/users/1084', 'pm_score': 0, 'selected': False, 'text': '<p>If you\'re concerned about this, it may be worthwhile to set the case to all upper or all lower before you check.<br>\nFor instance, in Perl:</p>\n\n<pre><code>$x = "abbCCDGBAdgfabv";\n(lc $x) =~ /bad/;\n</code></pre>\n\n<p>May in some cases be better than</p>\n\n<pre><code>$x = "abbCCDGBAdgfabv";\n$x =~ /bad/i;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/32010', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1384652/']