문제

브라우저 게임에서 좌표와 일치하고 싶습니다. 내 동선은 다음과 같습니다.

        try
        {
            Regex r = new Regex("Mond ([1-9]) \x5B([1-9]):([1-9][0-9]{0,2}):([1-9][0-9]{0,2})\x5D");
            Match m = r.Match("Mond 1 [1:1:1]");
        }
        catch (ArgumentException ex)
        {
            Console.WriteLine(ex);
        }

그리고 오류는 다음과 같습니다.

System.ArgumentException : "mond ([1-9]) [([1-9]) : ([1-9] [0-9] {0,2}) : ([1-9] [0-9 ] {0,2})] "Wird Analysiert -Zu Viele) -zeichen. bei system.text.regularexpressions.regexparser.scanregex () bei system.text.regularexpressions.regexparser.parse (String RE, RegexOptions OP) Bei System.text.regularexpressions.regex..ctor (문자열 패턴, RegexOptions 옵션, 부울 aSecache). bei windows formsapplication7.form22.combobox1_selectededIndexChanged (객체 발신자, EventArgs e) c : users HeavyFan visual studio 2008 projects WindowsFormsApplication7 Windows Formsapplication7 forms.cs : Zeile 27. Eine Ausnahme (Ererste fance) System System. .ArgumentException "System.dll aufgetreten의 ist.

내 동정형의 문제는 무엇입니까?

내 하찮은 영어 실력에 죄송하다는 말씀을 드리고 싶습니다. 결의안을위한 thx.

도움이 되었습니까?

해결책

오류 메시지를 이해하지 못했지만 탈출 문제처럼 보입니다. 백 슬래시를 피하지 않았습니다. Regex를 다음 중 하나로 변경하십시오.

//verbatim 
Regex r = new Regex(@"Mond ([1-9]) \x5B([1-9]):([1-9][0-9]{0,2}):([1-9][0-9]{0,2})\x5D");

//or escaped
Regex r = new Regex("Mond ([1-9]) \\x5B([1-9]):([1-9][0-9]{0,2}):([1-9][0-9]{0,2})\\x5D");

다른 팁

x5b 및 x5d는 각각 [및]로 변환되어 유효하지 않은 regex로 만듭니다.

직접 탈출하십시오. \[ and \].

두 배가 필요합니다 \ 캐릭터.

   try
    {
        Regex r = new Regex("Mond ([1-9]) \\x5B([1-9]):([1-9][0-9]{0,2}):([1-9][0-9]{0,2})\\x5D");
        Match m = r.Match("Mond 1 [1:1:1]");
    }
    catch (ArgumentException ex)
    {
        Console.WriteLine(ex);
    }

그리고 이것은 동일합니다

        Regex r = new Regex("Mond ([1-9]) \\[([1-9]):([1-9][0-9]{0,2}):([1-9][0-9]{0,2})\\]");

\x5B~이다 [ 그리고 \x5D ~이다 ]. 아는 것처럼 해당 캐릭터는 이미 Regex에서 의미를 가지고 있으므로 앞에 놓아서 탈출해야합니다. 구두 문자열을 사용하므로 를 사용할 필요가 없습니다.

new Regex(@"Mond ([1-9]) \[([1-9]):([1-9][0-9]{0,2}):([1-9][0-9]{0,2})\]")
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top