match multiple words instead of a single word

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?

Answers


You need to change the \w pattern (which matches alphanum plus underscore only) to something more liberal. For example this would also allow whitespace:

private string tokenRegEx = @"\[%RC:((\w|\s)+)%\].*?"; 

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.


Need Your Help

How many TCP sockets can I open at once?

windows sockets unix tcp operating-system

I am going to develop a tcp server application. I am on the "choose server" step.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.