Reputation: 36239
I have the following regular expression:
([0-9]+),'(.)':([0-9]+),(L|R|'.')
It matches this just fine:
1,'a':1,R
However, if I replace a with a space, it fails:
1,' ':1,R
Why doesn't . match it? Is a space not classified as a character? I can't use \s because I don't want to match tabs and line breaks. I also tried:
([0-9]+),'(.| )':([0-9]+),(L|R|'.')
But that doesn't work, either (and I don't have IgnorePatternWhitespace
enabled).
Upvotes: 2
Views: 396
Reputation: 1017
I haven't tried in .NET, but the dot is language and implementation specific. Try:
([0-9]+),'([.| ])':([0-9]+),(L|R|'.')
Upvotes: 0
Reputation: 1499830
I can't reproduce what you're seeing:
using System;
using System.Text.RegularExpressions;
class Test
{
static void Main()
{
Regex regex = new Regex("([0-9]+),'(.)':([0-9]+),(L|R|'.')");
Console.WriteLine(regex.IsMatch("1,' ':1,R"));
}
}
prints "True".
Is it possible that you've got another character between the quotes as well? Some non-printing character? Where is the text coming from?
You could try changing it to:
([0-9]+),'([^']+)':([0-9]+),(L|R|'.')
so it could match more than one character between the quotes.
Upvotes: 1