0

How i can use "/show_name=(.?)&show_name_exact=true\">(.?)

    Match m = Regex.Match(input, "/show_name=(.*?)&amp;show_name_exact=true\">(.*?)</i", RegexOptions.IgnoreCase);
   // Check Match instance
    if (m.Success)
    {
        // Get Group value
        string key = m.Groups[1].Value;
        Console.WriteLine(key);
        // alternate-1
    }

Error, Unterminated string literal(CS1039)] Error, Newline in constant(CS1010)]

What I am doing wrong?

1 Answer 1

3

I think you're mixing up .NET's regex syntax with PHP's. PHP requires you to use a regex delimiter in addition to the quotes that are required by the C# string literal. For instance, if you want to match "foo" case-insensitively in PHP you would use something like this:

'/foo/i'

...but C# doesn't require the extra regex delimiters, which means it doesn't support the /i style for adding match modifiers (that would have been redundant anyway, since you're also using the RegexOptions.IgnoreCase flag). I think this is what you're looking for:

@"show_name=(.*?)&amp;show_name_exact=true"">(.*?)<"

Note also how I escaped the internal quotation mark using another quotation mark instead of a backslash. You have to do it that way whether you use the old-fashioned string literal syntax or C#'s verbatim strings with the leading '@' (which is highly recommended for writing regexes). That's why you were getting the unterminated string error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.