i have the following regex:
private string tokenRegEx = @"\[%RC:(\w+)%\].*?";
which is when i pass in the string below it finds it:
[%RC:TEST%]
However the following returns false
[%RC:TEST ITEM%]
how can i modify the regex to allow for spaces as well as whole words?
You need to change the
\wpattern (which matches alphanum plus underscore only) to something more liberal. For example this would also allow whitespace:Of course the “correct” solution would need to take into account exactly what you consider acceptable input, which is kind of open to discussion at this point.