First of all, you need regex="{$regex}".
But also, you need to fix your regular expression, it's using many constructs that are not allowed in the XPath regular expression language, for example \B, (?i), (?-i).
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference