

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- How to get last 4 characters from string in C#?
- How to extract the last n characters from a string using Java?
- Python Program to Form a New String Made of the First 2 and Last 2 characters From a Given String
- MySQL query to get a substring from a string except the last three characters?
- How to match word characters using Java RegEx?
- How can I get last 4 characters of a string in Python?
- How to extract initial, last, or middle characters from a string in R?
- How to get last 12 digits from a string in MySQL?
- How to ORDER BY last 2 character string in MySQL?
- Matching Nonprintable Characters using Java regex
- Python Program to check if String contains only Defined Characters using Regex
- How to get odd and even position characters from a string?
- MySQL query to get substrings (only the last three characters) from strings?
- How to extract the last 4 characters from NSString?
- How to match a range of characters using Java regex
Advertisements