Reputation: 50094
This is a pretty simple question but I'm somewhat stumped.
I am capturing sections of text that match "xxxxxxxxxx". It works fine.
string pattern = "(?<quotePair>\"[^/\"]*\")";
Now I want to make a new pattern to capture “xxxxxxxxxx”... I used:
string pattern2 = "(?<lrquotePair>“[^/\"“]*”)";
For some reason the second pattern won't catch anything. What am I missing?
Upvotes: 0
Views: 1100
Reputation: 101665
Your patterns are more complicated than how you describe them - for example, the first one won't match "foo/bar"
, and the second one won't match “foo/bar”
or “foo"bar”
. Perhaps your input falls into one of those categories?
If there is an encoding problem, it's not with the regex - .NET regexes support Unicode just fine. But it might be that you didn't read the text in the correct encoding in the first place - try printing it out and check that the fancy “”
quotes are still there. In particular, if you use StreamReader
class with a single-argument constructor (or File.OpenText
helper), it defaults to UTF-8 encoding for input, which might not be what you actually have there.
Upvotes: 3
Reputation: 171924
There's nothing wrong with your second regex. Are you sure the input string is correct? The characters you're trying to match are not plain ASCII, so maybe there's a problem with a character encoding mismatch.
Upvotes: 0
Reputation: 11833
Encoding might be getting in your way. Try with \u0093
and \u0094
instead.
Upvotes: 1