
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
How to get last 2 characters from string in C# using Regex?
Set the string −
string str = "Cookie and Session";
Use the following Regex to get the last 2 characters from string −
Regex.Match(str,@"(.{2})\s*$")
The following is the code −
Example
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*$")); } }
Output
on
- Related Articles
- How to get last 4 characters from string in\nC#?
- How to extract the last n characters from a string using Java?
- MySQL query to get a substring from a string except the last three characters?
- How can I get last 4 characters of a string in Python?
- Golang Program to get characters from a string using the index
- How to extract initial, last, or middle characters from a string in R?
- How to match word characters using Java RegEx?
- How to get last 12 digits from a string in MySQL?
- Python Program to Form a New String Made of the First 2 and Last 2 characters From a Given String
- Python Program to check if String contains only Defined Characters using Regex
- How to use Regex to get the string between curly braces using JavaScript?
- How to get odd and even position characters from a string?
- How to match a range of characters using Java regex
- How to extract an HTML tag from a String using regex in Java?
- MySQL query to get substrings (only the last three characters) from strings?

Advertisements