A.D. A.D. - 1 year ago 79
C# Question

How to match boundary \b with accents

When I test on https://regex101.com/, if I leave standard options (/i)


will NOT find a match in text:

123 écumé 456

However, the match will be found if I add unicode flag:


How can I do that in C#? The following does find a match:

string pattern = "/\bécumé\b/iu"

Answer Source

As pointed out by @Callum, Regex101 does not support C#. If you try it in C#, it does work:

    public void TestMatch()
        // Arrange.
        const string example = "123 écumé 456";

        Regex pattern = new Regex(@"\bécumé\b");

        // Act.
        Match match = pattern.Match(example);

        // Assert.
        Assert.That(match.Success, Is.True);

Also to point out that when you say

the following does not find a match: "/\bécumé\b/iu"

The "/iu" in the string is not doing what you might think: in C# you can give regex options using a different parameter, not as part of the pattern string. For example:

Regex pattern = new Regex(@"\bécumé\b", RegexOptions.IgnoreCase);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download