Skip to content

[Bug]: Does not honour valid PCRE modifiers #3236

@lonix1

Description

@lonix1

Version

1.52.0

Steps to reproduce

using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Playwright;

class Program
{
    public static async Task Main()
    {
        using var playwright = await Playwright.CreateAsync();
        var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = true });
        var page = await browser.NewPageAsync();

        // .NET regex with inline (?i)
        var regex = new Regex(@"(?i).+\.css$");

        // Throws: Invalid regular expression: /(?i).+\.css$/: Invalid group
        await page.RouteAsync(regex, route => route.ContinueAsync());

        await browser.CloseAsync();
    }
}

Expected behavior

Playwright.NET should honour the PCRE / .NET regex.

At the very least, i, m and s.

Actual behavior

It doesn't.

Additional context

The regex @"(?i).+\.css$" includes the modifier (?i) which is the same as RegexOptions.IgnoreCase. It is preferable as that is embedded in the regex itself and can be easily transported across system boundaries as a simple string. It is standard PCRE.

JS is not PCRE compliant though, and requires the syntax /.+\.css$/i. For some reason Playwright is extracting the regex from the Regex instance and passing it directly to the browser, without checking for modifiers (and translating them to JS regex).

Environment

- Operating System: Ubuntu 24
- CPU: amd64
- Browser: All
- .NET Version: v8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions