SpecFlow does an automatic conversion when it's a string and you can't intercept that. From the docs:
The following conversions can be performed by SpecFlow (in the following precedence):
- no conversion, if the argument is an instance of the parameter type (e.g. the parameter type is object or string)
- step argument transformation
- standard conversion
A work-around would be to define a custom type with a single property to hold the custom string value:
public class CustomString
{
public string Value {get; set;}
}
Now you can use the attribute to convert a string that matches a certain regex to this custom class.
More information: http://www.specflow.org/documentation/Step-Argument-Conversions/