Computer >> 컴퓨터 >  >> 프로그램 작성 >> C++

Regex를 사용하여 C#의 문자열에서 마지막 2자를 얻는 방법은 무엇입니까?

<시간/>

문자열 설정 -

string str = "Cookie and Session";

다음 정규식을 사용하여 문자열에서 마지막 2자를 가져옵니다 -

Regex.Match(str,@"(.{2})\s*$")

다음은 코드입니다 -

예시

using System;
using System.Text.RegularExpressions;
public class Demo {
   public static void Main() {
      string str = "Cookie and Session";
      Console.WriteLine(Regex.Match(str,@"(.{2})\s*$"));
   }
}

출력

on