[Mono-list] Regex dosen't recognize \s or \w ?
clockworksaint at gmail.com
Wed Feb 4 19:23:26 UTC 2015
On 4 February 2015 at 15:03, mickeyf <mickey at thesweetoasis.com> wrote:
> I am using Monodevelop 188.8.131.52, with mono runtime 184.108.40.206 on Ubuntu 12.04
> When I try to include \s or \w in my regex, I get 'Unrecognized escape
> sequence', Otherwise regex works as I'd expect. (But I freely admit to
> having limited experience with regex.)
> What have I missed? Or if \s is not available, how do I specify "zero or
> more spaces" ?
It works fine for me. Here's a short example:
public class Program
static void Main()
Regex r = new Regex(@"^a\s*b$");
Action<string> testMatch =
(string s) =>
r.Match(s).Success ? "Matches" : "Does not match");
Have you forgotten to escape the backslashes in your string literal?
Are you seeing that error at compile-time? If so, it has nothing to do
with regular expressions. It means that you've broken the C# syntax
for writing strings. You either need to use a C# verbatim string,
which has an at-sign (@) in front of it, or you need to escape each
backslash by prefixing it with another backslash. See
Hope that helps.
More information about the Mono-list