Crashing CLR on SQL Server 2014 (windows 2012R2)
The problem is a locale conflict between the Windows OS and SQL Server (specifically the database where the Assembly is loaded). You can run the following query to see what they are both set to:

SELECT os_language_version,
       DATABASEPROPERTYEX(N'{name of DB where Assembly exists}', 'LCID') AS 'DatabaseLCID'
FROM   sys.dm_os_windows_info;


If they are different then you can definitely get some "odd" behavior, such as what you are seeing. The issue is that:


SqlString includes more than just the text itself: it includes the default collation of the database in which the assembly exists. The collation is comprised of two pieces of information: the locale info (i.e. LCID), and the comparison options (i.e. SqlCompareOptions) which detail the sensitivity to case, accents, kana, width, or everything (binary and binary2).
String operations in .NET, unless explicitly given a locale, use the locale info of the current thread, which is set in Windows (i.e. the Operating System / OS).


The conflict usually occurs when referencing a SqlString parameter without using .Value or .ToString() such that it does an implicit conversion to SqlString. In that case it would cause an exception saying that the LCIDs do not match.

There are apparently other scenarios, such as performing (some / all?) string comparisons, including when using Regex as this case shows (though so far I have not been able to reproduce this).

Some ideas for fixes:

Ideal (expectations will always be met regarding how the comparisons work):


Change either the Windows or SQL Server LCID (default language) so that both match


Less than ideal (the behavior of the Windows locale might not be the same rules for equality and sorting and so there could be unexpected results):


Use the .ToString method or .Value property, which both return the string without the SQL Server LCID so the operations will all be using the OS LCID.


Might help:


Maybe use SqlChars instead of SqlString as it does not bring along the LCID and collation info from SQL Server
Specify that culture doesn't matter via StringComparison.InvariantCulture:


String.Compare(string, string, StringComparison.InvariantCulture) or String.Compare(string, string, StringComparison.InvariantCultureIgnoreCase)
For Regex, specify RegexOptions.CultureInvariant